-
Notifications
You must be signed in to change notification settings - Fork 19
/
makefile.py
254 lines (190 loc) · 7.36 KB
/
makefile.py
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import os
import sys
import getopt
import shutil
import zipfile
import hashlib
import subprocess
import py_compile
sys.path[0:0] = [
os.path.abspath( os.path.join( os.path.split(sys.argv[0])[0], '..' ) ),
]
import keyhac_resource
#-------------------------------------------
action = "all"
debug = False
option_list, args = getopt.getopt( sys.argv[1:], "d" )
for option in option_list:
if option[0]=="-d":
debug = True
if len(args)>0:
action = args[0]
#-------------------------------------------
PYTHON_DIR = "c:/python38"
PYTHON = PYTHON_DIR + "/python.exe"
DOXYGEN_DIR = "c:/Program Files/doxygen"
DIST_DIR = "dist/keyhac"
VERSION = keyhac_resource.keyhac_version.replace(".","")
ARCHIVE_NAME = "keyhac_%s.zip" % VERSION
DIST_FILES = {
"keyhac.exe" : "keyhac/keyhac.exe",
"lib" : "keyhac/lib",
"python38.dll" : "keyhac/python38.dll",
"_config.py" : "keyhac/_config.py",
"readme_en.txt" : "keyhac/readme_en.txt",
"readme_ja.txt" : "keyhac/readme_ja.txt",
"theme/black" : "keyhac/theme/black",
"theme/white" : "keyhac/theme/white",
"license" : "keyhac/license",
"doc/html_en" : "keyhac/doc/en",
"doc/html_ja" : "keyhac/doc/ja",
"library.zip" : "keyhac/library.zip",
"dict/.keepme" : "keyhac/dict/.keepme",
"extension/.keepme" : "keyhac/extension/.keepme",
}
#-------------------------------------------
def unlink(filename):
try:
os.unlink(filename)
except OSError:
pass
def makedirs(dirname):
try:
os.makedirs(dirname)
except OSError:
pass
def rmtree(dirname):
try:
shutil.rmtree(dirname)
except OSError:
pass
def compilePythonRecursively( src, dst, file_black_list=[], directory_black_list=[] ):
for root, dirs, files in os.walk( src ):
for directory_to_remove in directory_black_list:
if directory_to_remove in dirs:
dirs.remove(directory_to_remove)
for file_to_remove in file_black_list:
if file_to_remove in files:
files.remove(file_to_remove)
for filename in files:
if filename.endswith(".py"):
src_filename = os.path.join(root,filename)
dst_filename = os.path.join(dst+root[len(src):],filename+"c")
print("compile", src_filename, dst_filename )
py_compile.compile( src_filename, dst_filename, optimize=2 )
def createZip( zip_filename, items ):
z = zipfile.ZipFile( zip_filename, "w", zipfile.ZIP_DEFLATED, True )
for item in items:
if os.path.isdir(item):
for root, dirs, files in os.walk(item):
for f in files:
f = os.path.normpath(os.path.join(root,f))
print( f )
z.write(f)
else:
print( item )
z.write(item)
z.close()
#-------------------------------------------
def target_all():
target_compile()
target_copy()
target_document()
target_dist()
target_archive()
def target_compile():
# compile python source files
compilePythonRecursively( "c:/python38/Lib", "build/Lib",
directory_black_list = [
"site-packages",
"test",
"tests",
"idlelib",
]
)
compilePythonRecursively( "c:/python38/Lib/site-packages/PIL", "build/Lib/PIL" )
compilePythonRecursively( "../ckit", "build/Lib/ckit" )
compilePythonRecursively( "../pyauto", "build/Lib/pyauto" )
compilePythonRecursively( ".", "build/Lib",
file_black_list = [
"makefile.py",
"_config.py",
"config.py",
]
)
# archive python compiled files
os.chdir("build/Lib")
createZip( "../../library.zip", "." )
os.chdir("../..")
def target_copy():
rmtree("lib")
shutil.copy( "c:/python38/python38.dll", "python38.dll" )
shutil.copytree( "c:/Python38/DLLs", "lib",
ignore=shutil.ignore_patterns(
"tcl*.*",
"tk*.*",
"_tk*.*",
"*.pdb",
"*_d.pyd",
"*_d.dll",
"*_test.pyd",
"_test*.pyd",
"*.ico",
"*.lib"
)
)
shutil.copy( "c:/Python38/Lib/site-packages/PIL/_imaging.cp38-win32.pyd", "lib/_imaging.pyd" )
shutil.copy( "../ckit/ckitcore.pyd", "lib/ckitcore.pyd" )
shutil.copy( "../pyauto/pyautocore.pyd", "lib/pyautocore.pyd" )
shutil.copy( "migemo.dll", "lib/migemo.dll" )
def target_document():
rmtree( "doc/html_en" )
rmtree( "doc/html_ja" )
makedirs( "doc/obj" )
makedirs( "doc/html_en" )
makedirs( "doc/html_ja" )
subprocess.call( [ PYTHON, "tool/rst2html_pygments.py", "--stylesheet=tool/rst2html_pygments.css", "doc/index_en.txt", "doc/obj/index_en.html" ] )
subprocess.call( [ PYTHON, "tool/rst2html_pygments.py", "--stylesheet=tool/rst2html_pygments.css", "--template=tool/rst2html_template.txt", "doc/index_en.txt", "doc/obj/index_en.htm_" ] )
subprocess.call( [ PYTHON, "tool/rst2html_pygments.py", "--stylesheet=tool/rst2html_pygments.css", "doc/index_ja.txt", "doc/obj/index_ja.html" ] )
subprocess.call( [ PYTHON, "tool/rst2html_pygments.py", "--stylesheet=tool/rst2html_pygments.css", "--template=tool/rst2html_template.txt", "doc/index_ja.txt", "doc/obj/index_ja.htm_" ] )
subprocess.call( [ PYTHON, "tool/rst2html_pygments.py", "--stylesheet=tool/rst2html_pygments.css", "doc/changes.txt", "doc/obj/changes.html" ] )
subprocess.call( [ PYTHON, "tool/rst2html_pygments.py", "--stylesheet=tool/rst2html_pygments.css", "--template=tool/rst2html_template.txt", "doc/changes.txt", "doc/obj/changes.htm_" ] )
subprocess.call( [ DOXYGEN_DIR + "/bin/doxygen.exe", "doc/doxyfile_en" ] )
shutil.copytree( "doc/image", "doc/html_en/image", ignore=shutil.ignore_patterns("*.pdn",) )
subprocess.call( [ DOXYGEN_DIR + "/bin/doxygen.exe", "doc/doxyfile_ja" ] )
shutil.copytree( "doc/image", "doc/html_ja/image", ignore=shutil.ignore_patterns("*.pdn",) )
def target_dist():
rmtree("dist/keyhac")
src_root = "."
dst_root = "./dist"
for src, dst in DIST_FILES.items():
src = os.path.join(src_root,src)
dst = os.path.join(dst_root,dst)
print( "copy : %s -> %s" % (src,dst) )
if os.path.isdir(src):
shutil.copytree( src, dst )
else:
makedirs( os.path.dirname(dst) )
shutil.copy( src, dst )
def target_archive():
makedirs("dist")
os.chdir("dist")
createZip( ARCHIVE_NAME, DIST_FILES.values() )
os.chdir("..")
fd = open( "dist/%s" % ARCHIVE_NAME, "rb" )
m = hashlib.md5()
while 1:
data = fd.read( 1024 * 1024 )
if not data: break
m.update(data)
fd.close()
print( "" )
print( m.hexdigest() )
def target_clean():
rmtree("dist")
rmtree("build")
rmtree("doc/html_en")
rmtree("doc/html_ja")
unlink( "tags" )
#-------------------------------------------
eval( "target_" + action +"()" )