-
Notifications
You must be signed in to change notification settings - Fork 14
/
make.py
300 lines (233 loc) · 9.41 KB
/
make.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# -*- coding: utf-8 -*-
from __future__ import with_statement
import os, sys, shutil, zipfile, platform
from contextlib import closing
from zipfile import ZipFile, ZIP_DEFLATED
#need Windows installer
#windows installer with console
#windows no install( include console)
#mac installer
#mac no installer
## Update odmtools.meta.data whenever creating a release
from odmtools.meta import data
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
SETUP_DIR = os.path.join(BASE_DIR, 'setup')
WIN_DIR = os.path.join(SETUP_DIR, "Windows")
MAC_DIR = os.path.join(SETUP_DIR, "Mac")
MAC_DIST_DIR = os.path.join(MAC_DIR, "Dist")
DIST_DIR = os.path.join(WIN_DIR, 'Dist')
MAC_WORK_DIR = os.path.join(MAC_DIR, "Temp")
WORK_DIR = os.path.join(WIN_DIR, "Temp")
ICON_DIR = os.path.join('odmtools', 'common', "icons")
WIN_ICON_FILE = os.path.join(ICON_DIR, "ODMTools.ico")
MAC_ICON_FILE = os.path.join(ICON_DIR, "ODMTools.icns")
APP_DIR = os.path.join(MAC_DIR, 'Dist', "ODMTools.app")
# Location of Windows files
APP_FILE = os.path.join(BASE_DIR, "ODMTools.py")
MAKE_FILE = os.path.realpath(__file__)
VERSION_FILE = os.path.join(SETUP_DIR, "version.txt")
# Location of Innosetup Installer
INNO_SCRIPT = os.path.join(WIN_DIR, "odmtools_setup.iss")
INNO_EXECUTABLE = '"C:\\Program Files (x86)\\Inno Setup 5\\ISCC.exe"'
ICE_SCRIPT = os.path.join(MAC_DIR, "ODMTools.packproj")
ICE_EXECUTABLE ='freeze'
def check_if_dirs_exist():
try:
if sys.platform == 'win32':
print "Trying to open WIN_DIR: ",
if not os.path.exists(WIN_DIR):
os.mkdir(WIN_DIR)
print "Created: ", WIN_DIR
print "Success"
print "Trying to confirm that INNO_SCRIPT exists: ",
assert os.path.exists(INNO_SCRIPT)
print "Success: ", INNO_SCRIPT
elif sys.platform =="darwin":
print "Trying to open MAC_DIR: "
assert os.path.exists(MAC_DIR)
print "Success"
print "Trying to open WORK_DIR: ",
if not os.path.exists(WORK_DIR):
print "Failed... Trying to create the folder...",
os.mkdir(WORK_DIR)
print "Created: ", WORK_DIR
print "Success"
print "Trying to open DIST_DIR: ",
if not os.path.exists(DIST_DIR):
print "Failed... Trying to create the folder...",
os.mkdir(DIST_DIR)
print "Created: ", DIST_DIR
print "Success"
print "Trying to open ICON_DIR: ",
assert os.path.exists(ICON_DIR)
print "Success"
except Exception as e:
print e
def zipdir(basedir, archivename):
assert os.path.isdir(basedir)
with closing(ZipFile(archivename, "w", ZIP_DEFLATED)) as z:
for root, dirs, files in os.walk(basedir):
#NOTE: ignore empty directories
for fn in files:
absfn = os.path.join(root, fn)
zfn = absfn[len(basedir)+len(os.sep):]
z.write(absfn, zfn)
def printInfo():
print "============================================================="
print "= ODMTools Installer "
print "= Be sure to update odmtools/meta/data with every release "
print "= Building release: {version}".format(version=data.version),
print "\n= Platform: {platform}, {architecture}".format(platform=sys.platform, architecture=platform.architecture()), "\n="
print "============================================================="
print "Environment Variables: "
print ("APP_FILE: ", APP_FILE)
print ("MAKE_FILE: ", MAKE_FILE)
print ("BASE_DIR: ", BASE_DIR)
print ("SETUP_DIR: ", SETUP_DIR)
print ("DIST_DIR: ", DIST_DIR)
## Windows Specific Files/Directories
print ("WIN_DIR: ", WIN_DIR)
print ("WIN_ICON_FILE: ", WIN_ICON_FILE)
print ("WORK_DIR: ", WORK_DIR)
print ("INNO_SCRIPT: ", INNO_SCRIPT)
print ("INNO_EXECUTABLE: ", INNO_EXECUTABLE)
## OSX Specific Files/Directories
print ("MAC_DIR: ", MAC_DIR)
print ("MAC_ICON_FILE: ", MAC_ICON_FILE)
print ("MAC_WORK_DIR: ", MAC_WORK_DIR)
print "============================================================="
print "Checking if the required directories exist"
check_if_dirs_exist()
def obtain_exe_filename(console=False):
if console:
return "{app}_{version}_{os}_{arch}_{type}".format(app=data.app_name,
version=data.version, os=sys.platform, arch='x86_64', type= "console")
else:
return "{app}_{version}_{os}_{arch}".format(app=data.app_name,
version=data.version, os=sys.platform, arch='x86_64')
def delete_old_out_dir():
loc_exists = os.path.exists(DIST_DIR)
isFile = os.path.isfile(DIST_DIR)
isDir = os.path.isdir(DIST_DIR)
if loc_exists and isFile:
print "Removing file DIST_DIR"
os.remove(DIST_DIR)
elif loc_exists and isDir:
print "Removing directory DIST_DIR"
shutil.rmtree(DIST_DIR)
else:
print "Nothing to remove"
def run_pyinstaller(console=False):
try:
if console:
## Console Version
command = """pyinstaller --clean --distpath=%s --workpath=%s --specpath=%s --icon=%s --version-file=%s --onefile --noconfirm %s""" % (WIN_DIR, WORK_DIR, WIN_DIR, WIN_ICON_FILE, VERSION_FILE, APP_FILE)
os.system(command)
else:
## Non Console Version
command = """pyinstaller --clean --distpath=%s --workpath=%s --specpath=%s --icon=%s --version-file=%s --onefile --noconsole --noconfirm %s""" % (
WIN_DIR, WORK_DIR, WIN_DIR, WIN_ICON_FILE, VERSION_FILE, APP_FILE)
os.system(command)
except Exception as e:
print (e)
return False
def mac_pyinstaller():
try:
#
# os.system('pyinstaller '
# '--clean '
# '--distpath=%s ' % MAC_DIST_DIR +
# '--workpath=%s ' % MAC_WORK_DIR +
# '--specpath=%s ' % MAC_DIR +
# '--upx-dir=%s ' % BASE_DIR +
# '--icon=%s ' % MAC_ICON_FILE +
# '--version-file=%s ' % VERSION_FILE +
# '--windowed '#'--onefile '
# '--noconfirm ' + APP_FILE)
command = """pyinstaller --clean --distpath=%s --workpath=%s --specpath=%s --noupx --icon=%s --version-file=%s --onefile --noconsole --noconfirm %s""" % (
MAC_DIST_DIR, MAC_WORK_DIR, MAC_DIR, MAC_ICON_FILE, VERSION_FILE, APP_FILE)
os.system(command)
#copy "libwx_osx_cocoau-3.0.0.0.0.dylib"
copycommand = "cp /anaconda/envs/odmtools/lib/libwx_osx_cocoau-3.0.0.0.0.dylib %s" % os.path.join(APP_DIR, "Contents/MacOS/")
os.system(copycommand)
copycommand = "cp /anaconda/envs/odmtools/lib/libmkl_avx2.dylib %s" % os.path.join(APP_DIR, "Contents/MacOS/")
os.system(copycommand)
return True
except Exception as e:
print (e)
return False
def move_to_dist(filename):
assert filename
if not os.path.isdir(DIST_DIR):
os.mkdir(DIST_DIR)
print "Moving {filename} to {dist}".format(filename=os.path.abspath(filename), dist=DIST_DIR),
try:
shutil.move(os.path.abspath(filename), DIST_DIR)
print "Success"
except shutil.Error as e:
print (e)
def run_inno(script = None):
if script is not None:
os.system(INNO_EXECUTABLE + " " + script)
else:
os.system(INNO_EXECUTABLE + " " + INNO_SCRIPT)
def run_no_installer():
# Need to finish, Not functional
raise ("Not functional yet")
filename = obtain_exe_filename()
zipdir(BASE_DIR, filename)
move_to_dist(filename)
def run_iceberg():
os.system(ICE_EXECUTABLE + " "+ ICE_SCRIPT)
def main():
delete_old_out_dir()
printInfo()
if sys.platform == 'win32':
print "Creating Windows Executable..."
if run_pyinstaller():
scriptpath = os.path.join(WIN_DIR, "odmtools_no_console.iss")
run_inno(script= scriptpath)
print "Creating Windows Executable Console..."
if run_pyinstaller(console=True):
scriptpath = os.path.join(WIN_DIR, "odmtools_console.iss")
run_inno(scriptpath)
print "Create No Installer "
## Create Shortcut
## Create File
## Zip Executable
elif sys.platform =='darwin':
if(mac_pyinstaller()):
run_iceberg()
# elif sys.platform == 'linux2':
# ## Testing, not officially supported
# run_no_installer()
if __name__ == '__main__':
main()
# OUT_DIR = os.path.join(BASE_DIR, 'dist')
# GTK_ZIP = os.path.join('tools', 'windows', 'gtk', 'gtk_to_copy.zip')
# INNO_SCRIPT = os.path.join('tools', 'config-inno.iss')
# INNO_EXECUTABLE = '"c:\\Program Files\\Inno Setup 5\\ISCC.exe"'
# class Unzip(object):
# def __init__(self, from_file, to_dir, verbose = False):
# """Removed for brevity, you can find a recipe similar to this in the Cook Book"""
# def run_pyinstaller():
# # A hack really, but remember setup.py will run on import
# sys.argv.append('py2exe')
# import setup
# def unzip_gtk():
# Unzip(GTK_ZIP, OUT_DIR)
# def run_inno():
# os.system(INNO_EXECUTABLE + " " + INNO_SCRIPT)
# def main():
# #Clean any mess we previously made
# delete_old_out_dir()
# # run py2exe
# run_py2exe()
# # put the GTK data files in the dist directory
# unzip_gtk()
# # build the single file installer
# run_inno()
# # prevent the windows command prompt from just closing
# raw_input('Done..')
# if __name__ == '__main__':
# main()