Skip to content

Commit b9f2e22

Browse files
committed
build_server: Code-formatting/readability fixes
- Wrap long code lines - Assemble long command strings from " ".join()-ed lists
1 parent 13ddbc4 commit b9f2e22

File tree

1 file changed

+109
-31
lines changed

1 file changed

+109
-31
lines changed

installer/build_server.py

+109-31
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ def run_command(command, working_dir=None):
8080
"""Utility function to return output from command line"""
8181
short_command = command.split('" ')[0] # We don't need to print args
8282
output("Running %s... (%s)" % (short_command, working_dir))
83-
p = subprocess.Popen(command, shell=True, cwd=working_dir,
84-
stdout=subprocess.PIPE,
85-
stderr=subprocess.STDOUT)
83+
p = subprocess.Popen(
84+
command,
85+
shell=True,
86+
cwd=working_dir,
87+
stdout=subprocess.PIPE,
88+
stderr=subprocess.STDOUT)
8689
return iter(p.stdout.readline, b"")
8790

8891

@@ -187,7 +190,7 @@ def upload(file_path, github_release):
187190
return url
188191

189192

190-
if __name__ == "__main__":
193+
def main():
191194
# Only run this code when directly executing this script. Parts of this file
192195
# are also used in the deploy.py script.
193196
try:
@@ -215,7 +218,12 @@ def upload(file_path, github_release):
215218
git_branch_name = sys.argv[7]
216219

217220
# Start log
218-
output("%s Build Log for %s (branch: %s)" % (platform.system(), datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), git_branch_name))
221+
output(
222+
"%s Build Log for %s (branch: %s)" % (
223+
platform.system(),
224+
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
225+
git_branch_name)
226+
)
219227

220228
# Detect artifact folder (if any)
221229
artifact_path = os.path.join(PATH, "build", "install-x64")
@@ -227,7 +235,8 @@ def upload(file_path, github_release):
227235

228236
# Parse artifact version files (if found)
229237
for repo_name in ["libopenshot-audio", "libopenshot", "openshot-qt"]:
230-
version_info.update(parse_version_info(os.path.join(artifact_path, "share", repo_name)))
238+
version_info.update(
239+
parse_version_info(os.path.join(artifact_path, "share", repo_name)))
231240
output(str(version_info))
232241

233242
# Get GIT description of openshot-qt-git branch (i.e. v2.0.6-18-ga01a98c)
@@ -279,12 +288,13 @@ def upload(file_path, github_release):
279288
os.makedirs(os.path.join(app_dir_path, "usr"), exist_ok=True)
280289

281290
# XDG Freedesktop icon paths
282-
icons = [ ("scalable", os.path.join(PATH, "xdg", "openshot-qt.svg")),
283-
("64x64", os.path.join(PATH, "xdg", "icon", "64", "openshot-qt.png")),
284-
("128x128", os.path.join(PATH, "xdg", "icon", "128", "openshot-qt.png")),
285-
("256x256", os.path.join(PATH, "xdg", "icon", "256", "openshot-qt.png")),
286-
("512x512", os.path.join(PATH, "xdg", "icon", "512", "openshot-qt.png")),
287-
]
291+
icons = [
292+
("scalable", os.path.join(PATH, "xdg", "openshot-qt.svg")),
293+
("64x64", os.path.join(PATH, "xdg", "icon", "64", "openshot-qt.png")),
294+
("128x128", os.path.join(PATH, "xdg", "icon", "128", "openshot-qt.png")),
295+
("256x256", os.path.join(PATH, "xdg", "icon", "256", "openshot-qt.png")),
296+
("512x512", os.path.join(PATH, "xdg", "icon", "512", "openshot-qt.png")),
297+
]
288298

289299
# Copy desktop icons
290300
icon_theme_path = os.path.join(app_dir_path, "usr", "share", "icons", "hicolor")
@@ -348,7 +358,11 @@ def upload(file_path, github_release):
348358

349359
# Create AppImage (OpenShot-%s-x86_64.AppImage)
350360
app_image_success = False
351-
for line in run_command('/home/ubuntu/apps/AppImageKit/AppImageAssistant "%s" "%s"' % (app_dir_path, app_build_path)):
361+
for line in run_command(" ".join([
362+
'/home/ubuntu/apps/AppImageKit/AppImageAssistant',
363+
'"%s"' % app_dir_path,
364+
'"%s"' % app_build_path,
365+
])):
352366
output(line)
353367
app_image_success = os.path.exists(app_build_path)
354368

@@ -361,23 +375,28 @@ def upload(file_path, github_release):
361375
# Delete build (since something failed)
362376
os.remove(app_build_path)
363377

364-
365378
if platform.system() == "Darwin":
366-
367379
# Create DMG (OpenShot-%s-x86_64.DMG)
368380
app_image_success = False
369381

370382
# Build app.bundle and create DMG
371383
for line in run_command("bash installer/build-mac-dmg.sh"):
372384
output(line)
373-
if ("error".encode("UTF-8") in line and "No errors".encode("UTF-8") not in line) or "rejected".encode("UTF-8") in line:
385+
if (
386+
("error".encode("UTF-8") in line
387+
and "No errors".encode("UTF-8") not in line)
388+
or "rejected".encode("UTF-8") in line
389+
):
374390
error("Build-Mac-DMG Error: %s" % line)
375391
if "Your image is ready".encode("UTF-8") in line:
376392
app_image_success = True
377393

378394
# Rename DMG (to be consistent with other OS installers)
379395
for dmg_path in os.listdir(os.path.join(PATH, "build")):
380-
if os.path.isfile(os.path.join(PATH, "build", dmg_path)) and dmg_path.endswith(".dmg"):
396+
if (
397+
os.path.isfile(os.path.join(PATH, "build", dmg_path))
398+
and dmg_path.endswith(".dmg")
399+
):
381400
os.rename(os.path.join(PATH, "build", dmg_path), app_build_path)
382401

383402
# Was the DMG creation successful
@@ -389,9 +408,7 @@ def upload(file_path, github_release):
389408
# Delete build (since key signing might have failed)
390409
os.remove(app_build_path)
391410

392-
393411
if platform.system() == "Windows":
394-
395412
# Move python folder structure, since Cx_Freeze doesn't put it in the correct place
396413
exe_dir = os.path.join(PATH, 'build', 'exe.mingw-3.7')
397414
python_dir = os.path.join(exe_dir, 'lib', 'python3.7')
@@ -402,7 +419,14 @@ def upload(file_path, github_release):
402419
shutil.rmtree(duplicate_openshot_qt_path, True)
403420

404421
# Remove the following paths. cx_Freeze is including many unneeded files. This prunes them out.
405-
paths_to_delete = ['mediaservice', 'imageformats', 'platforms', 'printsupport', 'lib/openshot_qt', 'resvg.dll']
422+
paths_to_delete = [
423+
'mediaservice',
424+
'imageformats',
425+
'platforms',
426+
'printsupport',
427+
'lib/openshot_qt',
428+
'resvg.dll',
429+
]
406430
for delete_path in paths_to_delete:
407431
full_delete_path = os.path.join(exe_dir, delete_path)
408432
output("Delete path: %s" % full_delete_path)
@@ -420,14 +444,24 @@ def upload(file_path, github_release):
420444
paths_to_replace = ['imageformats', 'platforms']
421445
for replace_name in paths_to_replace:
422446
if windows_32bit:
423-
shutil.copytree(os.path.join('C:\\msys32\\mingw32\\share\\qt5\\plugins', replace_name), os.path.join(exe_dir, replace_name))
447+
shutil.copytree(
448+
os.path.join('C:\\msys32\\mingw32\\share\\qt5\\plugins', replace_name),
449+
os.path.join(exe_dir, replace_name))
424450
else:
425-
shutil.copytree(os.path.join('C:\\msys64\\mingw64\\share\\qt5\\plugins', replace_name), os.path.join(exe_dir, replace_name))
451+
shutil.copytree(
452+
os.path.join('C:\\msys64\\mingw64\\share\\qt5\\plugins', replace_name),
453+
os.path.join(exe_dir, replace_name))
426454

427455
# Copy Qt5Core.dll, Qt5Svg.dll to root of frozen directory
428-
paths_to_copy = [("Qt5Core.dll", "C:\\msys64\\mingw64\\bin\\"), ("Qt5Svg.dll", "C:\\msys64\\mingw64\\bin\\")]
456+
paths_to_copy = [
457+
("Qt5Core.dll", "C:\\msys64\\mingw64\\bin\\"),
458+
("Qt5Svg.dll", "C:\\msys64\\mingw64\\bin\\"),
459+
]
429460
if windows_32bit:
430-
paths_to_copy = [("Qt5Core.dll", "C:\\msys32\\mingw32\\bin\\"), ("Qt5Svg.dll", "C:\\msys32\\mingw32\\bin\\")]
461+
paths_to_copy = [
462+
("Qt5Core.dll", "C:\\msys32\\mingw32\\bin\\"),
463+
("Qt5Svg.dll", "C:\\msys32\\mingw32\\bin\\"),
464+
]
431465
for qt_file_name, qt_parent_path in paths_to_copy:
432466
qt5_path = os.path.join(qt_parent_path, qt_file_name)
433467
new_qt5_path = os.path.join(exe_dir, qt_file_name)
@@ -452,7 +486,17 @@ def upload(file_path, github_release):
452486
# Add version metadata to frozen app launcher
453487
launcher_exe = os.path.join(exe_dir, "openshot-qt.exe")
454488
verpatch_success = True
455-
verpatch_command = '"verpatch.exe" "{}" /va /high "{}" /pv "{}" /s product "{}" /s company "{}" /s copyright "{}" /s desc "{}"'.format(launcher_exe, info.VERSION, info.VERSION, info.PRODUCT_NAME, info.COMPANY_NAME, info.COPYRIGHT, info.PRODUCT_NAME)
489+
verpatch_command = " ".join([
490+
'verpatch.exe',
491+
'{}'.format(launcher_exe),
492+
'/va',
493+
'/high "{}"'.format(info.VERSION),
494+
'/pv "{}"'.format(info.VERSION),
495+
'/s product "{}"'.format(info.PRODUCT_NAME),
496+
'/s company "{}"'.format(info.COMPANY_NAME),
497+
'/s copyright "{}"'.format(info.COPYRIGHT),
498+
'/s desc "{}"'.format(info.PRODUCT_NAME),
499+
])
456500
verpatch_output = ""
457501
# version-stamp executable
458502
for line in run_command(verpatch_command):
@@ -472,7 +516,13 @@ def upload(file_path, github_release):
472516

473517
# Create Installer (OpenShot-%s-x86_64.exe)
474518
inno_success = True
475-
inno_command = '"iscc.exe" /Q /DVERSION=%s /DONLY_64_BIT=%s "%s"' % (version, only_64_bit, os.path.join(PATH, 'installer', 'windows-installer.iss'))
519+
inno_command = " ".join([
520+
'iscc.exe',
521+
'/Q',
522+
'/DVERSION=%s' % version,
523+
'/DONLY_64_BIT=%s' % only_64_bit,
524+
'"%s"' % os.path.join(PATH, 'installer', 'windows-installer.iss'),
525+
])
476526
inno_output = ""
477527
# Compile Inno installer
478528
for line in run_command(inno_command):
@@ -495,7 +545,14 @@ def upload(file_path, github_release):
495545

496546
# Sign the installer
497547
key_sign_success = True
498-
key_sign_command = '"kSignCMD.exe" /f "%s%s" /p "%s" /d "OpenShot Video Editor" /du "http://www.openshot.org" "%s"' % (windows_key, only_64_bit, windows_key_password, app_build_path)
548+
key_sign_command = " ".join([
549+
'kSignCMD.exe',
550+
'/f "%s%s"' % (windows_key, only_64_bit),
551+
'/p "%s"' % windows_key_password,
552+
'/d "OpenShot Video Editor"',
553+
'/du "http://www.openshot.org"',
554+
'"%s"' % app_build_path,
555+
])
499556
key_sign_output = ""
500557
# Sign MSI
501558
for line in run_command(key_sign_command):
@@ -513,7 +570,6 @@ def upload(file_path, github_release):
513570
# Delete build (since key signing might have failed)
514571
os.remove(app_build_path)
515572

516-
517573
# Upload Installer to GitHub (if build path exists)
518574
if needs_upload and os.path.exists(app_build_path):
519575
# Upload file to GitHub
@@ -522,7 +578,19 @@ def upload(file_path, github_release):
522578

523579
# Create torrent and upload
524580
torrent_path = "%s.torrent" % app_build_path
525-
torrent_command = 'mktorrent -a "udp://tracker.openbittorrent.com:80/announce, udp://tracker.publicbt.com:80/announce, udp://tracker.opentrackr.org:1337" -c "OpenShot Video Editor %s" -w "%s" -o "%s" "%s"' % (version, download_url, "%s.torrent" % app_name, app_name)
581+
tracker_list = [
582+
"udp://tracker.openbittorrent.com:80/announce",
583+
"udp://tracker.publicbt.com:80/announce",
584+
"udp://tracker.opentrackr.org:1337",
585+
]
586+
torrent_command = " ".join([
587+
'mktorrent',
588+
'-a "%s"' % (", ".join(tracker_list)),
589+
'-c "OpenShot Video Editor %s"' % version,
590+
'-w "%s"' % download_url,
591+
'-o "%s"' % ("%s.torrent" % app_name),
592+
'"%s"' % app_name,
593+
])
526594
torrent_output = ""
527595

528596
# Remove existing torrents (if any found)
@@ -544,7 +612,10 @@ def upload(file_path, github_release):
544612
url = upload(torrent_path, github_release)
545613

546614
# Notify Zulip
547-
zulip_upload_log(zulip_token, log, "%s: Build logs for %s" % (platform.system(), app_name), "Successful *%s* build: %s" % (git_branch_name, download_url))
615+
zulip_upload_log(
616+
zulip_token, log,
617+
"%s: Build logs for %s" % (platform.system(), app_name),
618+
"Successful *%s* build: %s" % (git_branch_name, download_url))
548619

549620
except Exception as ex:
550621
tb = traceback.format_exc()
@@ -555,5 +626,12 @@ def upload(file_path, github_release):
555626
else:
556627
# Report any errors detected
557628
output("build-server script failed!")
558-
zulip_upload_log(zulip_token, log, "%s: Error log for *%s* build" % (platform.system(), git_branch_name), ":skull_and_crossbones: %s" % truncate(errors_detected[0], 100))
629+
zulip_upload_log(
630+
zulip_token, log,
631+
"%s: Error log for *%s* build" % (platform.system(), git_branch_name),
632+
":skull_and_crossbones: %s" % truncate(errors_detected[0], 100))
559633
exit(1)
634+
635+
636+
if __name__ == "__main__":
637+
main()

0 commit comments

Comments
 (0)