-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.py
executable file
·232 lines (160 loc) · 9.8 KB
/
deploy.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
#!/usr/bin/env python3
import argparse, glob, os, platform, shutil, subprocess, stat, sys, urllib.request
def run_command(command):
if platform.system() != 'Windows' and os.sep in command[0] and not os.path.isfile(command[0]):
sys.exit('error: failed to locate {}'.format(os.path.basename(command[0])))
if subprocess.call(command) != 0:
sys.exit('error: failed to execute "{}"'.format(' '.join(command)))
def escape_windows_executable_path(executable_path):
if ' ' not in executable_path:
return executable_path
segments = executable_path.split('\\')
escaped_segments = []
for segment in segments:
if ' ' in segment:
segment = '"{}"'.format(segment)
escaped_segments.append(segment)
return '\\'.join(escaped_segments)
def make_path(root, directories):
if not os.path.exists(root):
os.mkdir(root)
for directory in directories:
root = os.path.join(root, directory)
if not os.path.exists(root):
os.mkdir(root)
def get_executable(name, url=None, tools_path=None, is_optional=False):
exectable_path = None
if tools_path != None:
exectable_path = os.path.join(tools_path, name)
if os.path.isfile(exectable_path):
return exectable_path
for directory in os.getenv('PATH', '').split(os.pathsep):
possible_exectable_path = os.path.join(directory, name)
if os.path.isfile(possible_exectable_path) and os.access(possible_exectable_path, os.X_OK):
return possible_exectable_path
if tools_path != None and url != None:
print('info: downloading {} from {}'.format(name, url))
urllib.request.urlretrieve(url, exectable_path)
os.chmod(exectable_path, os.stat(exectable_path).st_mode | stat.S_IEXEC)
if not is_optional and exectable_path == None:
sys.exit('error: failed to locate {}'.format(name))
return exectable_path
def deploy_locale(source_path, target_path):
target_locale_path = os.path.join(target_path, 'locale')
os.mkdir(target_locale_path)
for file in glob.glob(os.path.join(source_path, 'resources', 'translations', '*.qm')):
shutil.copy(file, target_locale_path)
def deploy_linux(arguments):
tools_path = None
if not arguments.disable_tools_download:
tools_path = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), 'appimage-tools')
if not os.path.isdir(tools_path):
os.mkdir(tools_path)
appdir_deploy_command = get_executable('linuxdeploy-x86_64.AppImage', 'https://bintray.com/qtproject/linuxdeploy-mirror/download_file?file_path=2020-06-03%2Flinuxdeploy-x86_64.AppImage', tools_path)
appimage_tool_command = get_executable('appimagetool-x86_64.AppImage', 'https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage', tools_path)
get_executable('linuxdeploy-plugin-qt-x86_64.AppImage', 'https://bintray.com/qtproject/linuxdeploy-mirror/download_file?file_path=2020-06-03%2Flinuxdeploy-plugin-qt-x86_64.AppImage', tools_path)
appimage_path = os.path.join(arguments.target_path, 'otter-browser')
make_path(appimage_path, ['usr', 'share', 'applications'])
make_path(appimage_path, ['usr', 'share', 'icons', 'hicolor'])
make_path(appimage_path, ['usr', 'share', 'otter-browser'])
shutil.copy(os.path.join(arguments.source_path, 'otter-browser.desktop'), os.path.join(appimage_path, 'usr/share/applications/otter-browser.desktop'))
icons_path = os.path.join(appimage_path, 'usr/share/icons/hicolor')
icons = [16, 32, 48, 64, 128, 256, 'scalable']
for size in icons:
is_raster = isinstance(size, int)
icon_directory = '{}x{}'.format(size, size) if is_raster else size
make_path(icons_path, [icon_directory, 'apps'])
shutil.copy(os.path.join(arguments.source_path, 'resources/icons', 'otter-browser-{}.png'.format(size) if is_raster else 'otter-browser.svg'), os.path.join(icons_path, icon_directory, 'apps', 'otter-browser.png' if is_raster else 'otter-browser.svg'))
deploy_locale(arguments.source_path, os.path.join(appimage_path, 'usr/share/otter-browser'))
os.putenv('LD_LIBRARY_PATH', '{}:{}'.format(os.path.join(arguments.qt_path, 'lib'), os.getenv('LD_LIBRARY_PATH')))
os.putenv('QMAKE', os.path.join(arguments.qt_path, 'bin/qmake'))
run_command([appdir_deploy_command, '--plugin=qt', '--executable={}'.format(os.path.join(arguments.build_path, 'otter-browser')), '--appdir={}'.format(appimage_path)])
shutil.rmtree(os.path.join(appimage_path, 'usr/share/doc/'), ignore_errors=True)
libs_path = os.path.join(appimage_path, 'usr/lib')
redundant_libs = ['libgst*-1.0.*', 'libFLAC.*', 'libogg.*', 'libvorbis*.*', 'libmount.*', 'libpulse*.*', 'libsystemd.*', 'libxml2.*']
for pattern in redundant_libs:
for file in glob.glob(os.path.join(libs_path, pattern)):
os.unlink(file)
for file in glob.glob(os.path.join(libs_path, 'libicu*.*')):
if not os.path.exists(os.path.join(arguments.qt_path, 'lib', os.path.basename(file))):
os.unlink(file)
run_command([appimage_tool_command, appimage_path, os.path.join(arguments.target_path, 'otter-browser-x86_64.AppImage')])
if not arguments.preserve_deployment_directory:
shutil.rmtree(appimage_path)
def deploy_macos(arguments):
macdeployqt_command = os.path.join(arguments.qt_path, 'bin/macdeployqt')
if not os.path.isfile(macdeployqt_command):
sys.exit('error: failed to locate "{}"'.format(macdeployqt_command))
app_path = os.path.join(arguments.target_path, 'OtterBrowser.app')
shutil.copytree(os.path.join(arguments.build_path, 'Otter Browser.app'), app_path)
run_command([macdeployqt_command, app_path])
run_command(['zip', '-r', 'OtterBrowser.zip', app_path])
def deploy_windows(arguments):
windeployqt_command = os.path.join(arguments.qt_path, r'bin\windeployqt.exe')
seven_z_command = r'C:\Program Files\7-Zip\7z.exe'
inno_setup_command = r'C:\Program Files (x86)\Inno Setup 6\ISCC.exe'
if not os.path.isfile(windeployqt_command):
sys.exit('error: failed to locate "{}"'.format(windeployqt_command))
if not os.path.isfile(seven_z_command):
seven_z_command = get_executable('7z.exe', is_optional=True)
if not os.path.isfile(inno_setup_command):
inno_setup_command = get_executable('ISCC.exe')
target_installer_path = os.path.join(arguments.target_path, 'input')
os.mkdir(target_installer_path)
shutil.copy(os.path.join(arguments.build_path, 'otter-browser.exe'), target_installer_path)
shutil.copy(os.path.join(arguments.source_path, 'COPYING'), target_installer_path)
deploy_locale(arguments.source_path, os.path.join(arguments.target_path, 'input'))
run_command([escape_windows_executable_path(windeployqt_command), os.path.join(arguments.target_path, r'input\otter-browser.exe')])
dlls_path = os.path.join(arguments.qt_path, 'bin')
extra_dlls = ['libxml2*.dll', 'libxslt*.dll']
for pattern in extra_dlls:
for file in glob.glob(os.path.join(dlls_path, pattern)):
shutil.copy(file, target_installer_path)
for pattern in arguments.extra_libs:
matches = glob.glob(pattern)
if len(matches) == 0:
sys.exit('error: failed to locate {}'.format(pattern))
for file in matches:
shutil.copy(file, target_installer_path)
redundant_plugins = ['playlistformats', 'position', 'qmltooling', 'scenegraph', 'sensorgestures', 'sensors']
for directory in redundant_plugins:
shutil.rmtree(os.path.join(target_installer_path, directory), ignore_errors=True)
inno_setup_arguments = '/DOtterWorkingDir="{}"'.format(arguments.target_path)
if '_64' in arguments.qt_path[-5:]:
inno_setup_arguments += ' /DOtterWin64=1'
os.system('{} {} "{}"'.format(escape_windows_executable_path(inno_setup_command), inno_setup_arguments, os.path.join(arguments.source_path, r'packaging\otter-browser.iss')))
release_name = 'otter-browser'
for file in glob.glob(os.path.join(arguments.target_path, '*.exe')):
release_name = os.path.splitext(os.path.basename(file))[0].replace('-setup', '')
break
target_release_path = os.path.join(arguments.target_path, release_name)
os.rename(target_installer_path, target_release_path)
if arguments.enable_portable:
with open(os.path.join(target_release_path, 'arguments.txt'), 'w') as file:
file.write('--portable')
# if seven_z_command != None:
# run_command([seven_z_command, 'a', '{}.7z'.format(os.path.join(arguments.target_path, release_name)), target_release_path])
#
# run_command(['powershell', 'Compress-Archive', '"{}"'.format(target_release_path), '"{}.zip"'.format(os.path.join(arguments.target_path, release_name))])
if not arguments.preserve_deployment_directory:
shutil.rmtree(target_release_path)
#shutil.copy(os.path.join(arguments.build_path, 'otter-browser.pdb'), os.path.join(arguments.target_path, release_name + '.pdb'))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Otter Browser deployment tool.')
parser.add_argument('--build-path', help='Path to the build directory', default=os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../build')))
parser.add_argument('--source-path', help='Path to the source directory', default=os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..')))
parser.add_argument('--target-path', help='Path to the output directory', default=os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../output')))
parser.add_argument('--qt-path', help='Path to the Qt directory', default=os.getenv('QTDIR', ''))
parser.add_argument('--extra-libs', help='Paths to the extra libraries to include', default=[], nargs='*')
parser.add_argument('--enable-portable', help='Force portable mode', action='store_true')
parser.add_argument('--disable-tools-download', help='Disable download of missing deployment tools', action='store_true')
parser.add_argument('--preserve-deployment-directory', help='Preserve deployment directory after creating packages', action='store_true')
arguments = parser.parse_args()
if arguments.qt_path == '':
sys.exit('error: the following arguments are required: --qt-path')
if platform.system() == 'Linux':
deploy_linux(arguments)
elif platform.system() == 'Darwin':
deploy_macos(arguments)
elif platform.system() == 'Windows':
deploy_windows(arguments)