-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstallers.py
executable file
·240 lines (207 loc) · 9.12 KB
/
installers.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
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function
from os.path import dirname, realpath, join, exists, normpath
import utool as ut
import sys
from os.path import join # NOQA
def get_setup_dpath():
assert exists('../gzc-client'), 'must be run in gzc-client directory'
cwd = normpath(realpath(dirname(__file__)))
return cwd
def clean_pyinstaller():
print('[installer] +--- CLEAN_PYINSTALLER ---')
cwd = get_setup_dpath()
ut.remove_files_in_dir(cwd, 'GZCClient.pkg', recursive=False)
ut.remove_files_in_dir(cwd, 'GZCClientApp.pkg', recursive=False)
ut.delete(join(cwd, 'dist/gzc-client'))
ut.delete(join(cwd, 'gzc-client-win32-setup.exe'))
ut.delete(join(cwd, 'build'))
ut.delete(join(cwd, 'dist'))
ut.delete(join(cwd, 'qt_menu.nib'))
print('[installer] L___ FINSHED CLEAN_PYINSTALLER ___')
def build_pyinstaller():
"""
build_pyinstaller creates build/gzc-client/* and dist/gzc-client/*
"""
print('[installer] +--- BUILD_PYINSTALLER ---')
import os # NOQA
# 1) RUN: PYINSTALLER
# Run the pyinstaller command (does all the work)
if sys.platform == 'win32' or sys.platform == 'cygwin':
#ut.cmd('pyinstaller', '--runtime-hook', 'rthook_pyqt4.py', '_installers/pyinstaller-client.spec', '-y')
ut.cmd('pyinstaller --runtime-hook rthook_pyqt4.py _installers/pyinstaller-client.spec -y')
else:
ut.cmd('pyinstaller', '_installers/pyinstaller-client.spec', '-y')
#ut.cmd('pyinstaller', '--runtime-hook rthook_pyqt4.py', '_installers/pyinstaller-client.spec')
# 2) POST: PROCESSING
# Perform some post processing steps on the mac
if sys.platform == 'darwin' and exists('dist/GZCClient.app/Contents/'):
copy_list = [
('ibsicon.icns', 'Resources/icon-windowed.icns'),
('Info.plist', 'Info.plist'),
]
srcdir = '_installers'
dstdir = 'dist/GZCClient.app/Contents/'
for srcname, dstname in copy_list:
src = join(srcdir, srcname)
dst = join(dstdir, dstname)
ut.copy(src, dst)
print('[installer] L___ FINISH BUILD_PYINSTALLER ___')
def ensure_inno_isinstalled():
""" Ensures that the current machine has INNO installed. returns path to the
executable """
assert ut.WIN32, 'Can only build INNO on windows'
inno_fpath = ut.search_in_dirs('Inno Setup 5\ISCC.exe', ut.get_install_dirs())
# Make sure INNO is installed
if inno_fpath is None:
print('WARNING: cannot find inno_fpath')
AUTO_FIXIT = ut.WIN32
print('Inno seems to not be installed. AUTO_FIXIT=%r' % AUTO_FIXIT)
if AUTO_FIXIT:
print('Automaticaly trying to downoad and install INNO')
# Download INNO Installer
inno_installer_url = 'http://www.jrsoftware.org/download.php/ispack.exe'
inno_installer_fpath = ut.download_url(inno_installer_url)
print('Automaticaly trying to install INNO')
# Install INNO Installer
ut.cmd(inno_installer_fpath)
else:
inno_homepage_url = 'http://www.jrsoftware.org/isdl.php'
ut.open_url_in_browser(inno_homepage_url)
raise AssertionError('Cannot find INNO and AUTOFIX it is false')
# Ensure that it has now been installed
inno_fpath = ut.search_in_dirs('Inno Setup 5\ISCC.exe', ut.get_install_dirs())
assert ut.checkpath(inno_fpath, verbose=True, info=True), 'inno installer is still not installed!'
return inno_fpath
def ensure_inno_script():
""" writes inno script to distk """
cwd = get_setup_dpath()
iss_script_fpath = join(cwd, '_installers', 'win_installer_script.iss')
# THE ISS USES {} AS SYNTAX. CAREFUL
#app_publisher = 'Rensselaer Polytechnic Institute'
#app_name = 'GZCClient'
iss_script_code = ut.codeblock(
'''
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
; http://www.jrsoftware.org/isdl.php
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{47BE3DA2-261D-4672-9849-18BB2EB382FC}
AppName=GZCClient
AppVersion=1
;AppVerName=GZCClient 1
AppPublisher=Rensselaer Polytechnic Institute
AppPublisherURL=ibeis.org
AppSupportURL=ibeis.org
AppUpdatesURL=ibeis.org
DefaultDirName={pf}\GZCClient
DefaultGroupName=GZCClient
OutputBaseFilename=gzc-client-win32-setup
SetupIconFile=ibsicon.ico
Compression=lzma
SolidCompression=yes
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "..\dist\gzc-client\GZCClientApp.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\dist\gzc-client\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\gzc-client"; Filename: "{app}\GZCClientApp.exe"
Name: "{commondesktop}\gzc-client"; Filename: "{app}\GZCClientApp.exe"; Tasks: desktopicon
[Run]
Filename: "{app}\GZCClientApp.exe"; Description: "{cm:LaunchProgram,GZCClient}"; Flags: nowait postinstall skipifsilent
'''
)
ut.write_to(iss_script_fpath, iss_script_code, onlyifdiff=True)
assert ut.checkpath(iss_script_fpath, verbose=True, info=True), 'cannot find iss_script_fpath'
return iss_script_fpath
def inno_installer_postprocess():
""" Move the built installer into a more reasonable directory """
try:
cwd = get_setup_dpath()
installer_src = join(cwd, '_installers', 'Output', 'gzc-client-win32-setup.exe')
installer_dst = join(cwd, 'dist', 'gzc-client-win32-setup.exe')
# Make a timestamped version
timestamped_fname = 'gzc-client-win32-setup-{timestamp}.exe'.format(timestamp=ut.get_timestamp())
installer_dst2 = join(cwd, 'dist', timestamped_fname)
ut.move(installer_src, installer_dst)
ut.copy(installer_dst, installer_dst2)
except Exception as ex:
ut.printex(ex, 'error moving setups', iswarning=True)
def build_win32_inno_installer():
""" win32 self-executable package """
print('[installer] +--- BUILD_WIN32_INNO_INSTALLER ---')
assert ut.WIN32, 'Can only build INNO on windows'
# Get inno executable
inno_fpath = ensure_inno_isinstalled()
# Get GZCClient inno script
iss_script_fpath = ensure_inno_script()
print('Trying to run ' + ' '.join(['"' + inno_fpath + '"', '"' + iss_script_fpath + '"']))
try:
command_args = ' '.join((inno_fpath, iss_script_fpath))
ut.cmd(command_args)
except Exception as ex:
ut.printex(ex, 'error running script')
raise
# Move the installer into dist and make a timestamped version
inno_installer_postprocess()
# Uninstall exe in case we need to cleanup
#uninstall_gzc-client_exe = 'unins000.exe'
print('[installer] L___ BUILD_WIN32_INNO_INSTALLER ___')
def package_installer():
"""
system dependent post pyinstaller step
"""
print('[installer] +--- PACKAGE_INSTALLER ---')
#build_win32_inno_installer()
if sys.platform.startswith('win32'):
build_win32_inno_installer()
elif sys.platform.startswith('darwin'):
ut.cmd('./_installers/mac_dmg_builder.sh', sudo=True)
pass
elif sys.platform.startswith('linux'):
raise NotImplementedError('no linux packager (rpm or deb) supported. try running with --build')
pass
print('[installer] L___ FINISH PACKAGE_INSTALLER ___')
def test_app():
print('[installer] +--- TEST_APP ---')
ut.cmd(ut.unixpath('dist/gzc-client/GZCClientApp.exe'))
print('[installer] L___ FINISH TEST_APP ___')
#ut.cmd(ut.unixpath('dist/gzc-client/gzc-client-win32-setup.exe'))
def main():
"""
CommandLine:
python installers.py --all
python installers.py --inno
"""
print('For a full run use: python installers.py --all')
print('[installer] +--- MAIN ---')
BUILD_APP = ut.get_argflag(('--build'))
BUILD_INSTALLER = ut.get_argflag(('--inno', '--package', '--pkg'))
TEST_APP = ut.get_argflag(('--test'))
CLEAN_BUILD = ut.get_argflag(('--clean'))
ALL = ut.get_argflag('--all')
# default behavior is full build
BUILD_ALL = ALL or not (BUILD_APP or BUILD_INSTALLER or TEST_APP)
# 1) SETUP: CLEAN UP
if CLEAN_BUILD or BUILD_ALL:
clean_pyinstaller()
if BUILD_APP or BUILD_ALL:
build_pyinstaller()
if BUILD_INSTALLER or BUILD_ALL:
package_installer()
# if TEST_APP or BUILD_ALL:
# test_app()
print('[installer] L___ FINISH MAIN ___')
if __name__ == '__main__':
main()
'''
dist\gzc-client-win32-setup.exe
dist\gzc-client\GZCClientApp.exe
'''