-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_python.py
More file actions
167 lines (100 loc) · 3.79 KB
/
install_python.py
File metadata and controls
167 lines (100 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Nick Hilton
# 2013-10-05
#
# Installs a Python build from the Visual Studio directory to target directory
#
import glob
import os
import shutil
import sys
import os.path
from os.path import dirname
from os.path import abspath
#------------------------------------------------------------------------------
# Globals
EXTERNALS_DIR = dirname(abspath(__file__))
PYTHON_DIR = "."
TCLTK_DIR = EXTERNALS_DIR+"\..\\tcltk"
DST_DIR = r"C:\Python27"
def make_directory(d):
if not os.path.exists(d):
print "Creating directory: %s" % repr(d)
os.makedirs(d)
def copy_files(filelist, dst):
for f in filelist:
f = f.replace('/', '\\')
f, ext = os.path.splitext(f)
for ext_ in [ext, '_d' + ext]:
f_ = f + ext_
if os.path.isfile(f_):
print "Copying %s --> %s" % (f_, dst)
shutil.copy(f_, dst)
def copy_directory(src_dir, dst_dir):
if not os.path.isdir(src_dir):
raise RuntimeError("Oops, couldn't find path: %s" % repr(src_dir))
if os.path.isdir(dst_dir):
shutil.rmtree(dst_dir)
print "Copying %s --> %s" % (src_dir, dst_dir)
shutil.copytree(src_dir, dst_dir)
if __name__ == "__main__":
print "EXTERNALS_DIR =", EXTERNALS_DIR
print "PYTHON_DIR =", PYTHON_DIR
print "TCLTK_DIR =", TCLTK_DIR
for p in [EXTERNALS_DIR, PYTHON_DIR, TCLTK_DIR]:
if not os.path.isdir(p):
raise RuntimeError("Oops, could not find path: %s" % repr(p))
#--------------------------------------------------------------------------
# Create destination directory
if DST_DIR is None:
DST_DIR = r"C:\Python27"
d = raw_input("Enter destination directory [%s]: " % repr(DST_DIR))
if len(d) > 0:
DST_DIR = d
print "DST_DIR =", DST_DIR
make_directory(DST_DIR)
#--------------------------------------------------------------------------
# copy python.exe
SRC_DIR = os.path.join(EXTERNALS_DIR, PYTHON_DIR)
PCBUILD_DIR = "{SRC_DIR}/PCbuild".format(SRC_DIR = SRC_DIR)
filelist = """
{py_prefix}/python.exe
{py_prefix}/pythonw.exe
{py_prefix}/python27.dll
""".format(py_prefix = PCBUILD_DIR).split()
copy_files(filelist, DST_DIR)
#--------------------------------------------------------------------------
# copy DLLs
src_list = glob.glob(PCBUILD_DIR + r"\*.pyd")
dst_dir = os.path.join(DST_DIR, "DLLs")
make_directory(dst_dir)
copy_files(src_list, dst_dir)
# Tcl dlls
src_list = glob.glob(TCLTK_DIR + r"\bin\*.dll")
copy_files(src_list, dst_dir)
#--------------------------------------------------------------------------
# copy include
src_dir = os.path.join(SRC_DIR, "Include")
dst_dir = os.path.join(DST_DIR, "include")
copy_directory(src_dir, dst_dir)
src_list = ["{SRC_DIR}/PC/pyconfig.h".format(SRC_DIR = SRC_DIR)]
copy_files(src_list, dst_dir)
#--------------------------------------------------------------------------
# copy Lib
src_dir = os.path.join(SRC_DIR, "Lib")
dst_dir = os.path.join(DST_DIR, "Lib")
copy_directory(src_dir, dst_dir)
#--------------------------------------------------------------------------
# copy libs
src_list = glob.glob(PCBUILD_DIR + r"\*.lib")
dst_dir = os.path.join(DST_DIR, "libs")
make_directory(dst_dir)
copy_files(src_list, dst_dir)
#--------------------------------------------------------------------------
# Scripts dir
make_directory(os.path.join(DST_DIR, "Scripts"))
#--------------------------------------------------------------------------
# tcl
src_dir = os.path.join(EXTERNALS_DIR, TCLTK_DIR, "lib")
dst_dir = os.path.join(DST_DIR, "tcl")
copy_directory(src_dir, dst_dir)
print "All done!"