Skip to content

Commit 3cf7717

Browse files
committed
deploy.py: Reformat long lines
1 parent 2a89045 commit 3cf7717

File tree

1 file changed

+99
-42
lines changed

1 file changed

+99
-42
lines changed

installer/deploy.py

+99-42
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
urllib3.disable_warnings()
5151

5252

53-
if __name__ == "__main__":
53+
def main():
5454
# Only run this code when directly executing this script.
5555

5656
zulip_token = None
@@ -82,15 +82,18 @@
8282
script_mode = "publish"
8383

8484
# Start log
85-
output("%s %s Log for %s" % (platform.system(), script_mode,
86-
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
85+
output("%s %s Log for %s" % (
86+
platform.system(),
87+
script_mode,
88+
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
8789

8890
# Detect artifact folder (if any)
8991
artifact_dir = os.path.join(PATH, "build")
9092

9193
# Parse artifact version files (if found)
9294
for repo_name in repo_names:
93-
version_info.update(parse_version_info(os.path.join(artifact_dir, "install-x64", "share", repo_name)))
95+
version_info.update(parse_version_info(
96+
os.path.join(artifact_dir, "install-x64", "share", repo_name)))
9497
output(str(version_info))
9598

9699
# Get version info
@@ -104,8 +107,9 @@
104107
original_git_branch = git_branch_name
105108
if original_git_branch != git_branch_name:
106109
# Branch names do not match
107-
raise Exception("Branch names do not match for all 3 repos: `%s` vs `%s`" %
108-
(original_git_branch, git_branch_name))
110+
raise Exception(
111+
"Branch names do not match for all 3 repos: `%s` vs `%s`" %
112+
(original_git_branch, git_branch_name))
109113

110114
# Loop through and get and/or create the GitHub Release objects
111115
releases = {}
@@ -122,14 +126,18 @@
122126
# Get official version release (i.e. v2.1.0, v2.x.x)
123127
releases[repo_name] = get_release(repos.get(repo_name), github_release_name)
124128
if releases.get(repo_name) and releases.get(repo_name).prerelease is False:
125-
raise Exception("GitHub release for version %s is already released. Did we forget to bump a "
126-
"version? (repo: %s, branch: %s)" % (github_release_name, repo_name,
127-
git_branch_name))
129+
raise Exception(
130+
"GitHub release for version %s is already released. Did we forget to bump a "
131+
"version? (repo: %s, branch: %s)" % (
132+
github_release_name, repo_name,
133+
git_branch_name)
134+
)
128135
else:
129136
# ignore all branches that don't start with 'release*'
130-
raise Exception("%s only allowed for branch names that start with 'release*'"
131-
" (repo: %s, branch: %s)" %
132-
(script_mode, repo_name, git_branch_name))
137+
raise Exception(
138+
"%s only allowed for branch names that start with 'release*'"
139+
" (repo: %s, branch: %s)" % (
140+
script_mode, repo_name, git_branch_name))
133141

134142
if not is_publish:
135143

@@ -152,9 +160,11 @@
152160
so_title = ""
153161
if so_number:
154162
so_title = ", SO: %s" % so_number
155-
log_markdown = "%s Changelog (Version: %s%s)\n---\n%s\n\n" % \
156-
(repo_name, version_info.get(repo_name, {}).get('VERSION'),
157-
so_title, logs.get(repo_name))
163+
log_markdown = "%s Changelog (Version: %s%s)\n---\n%s\n\n" % (
164+
repo_name,
165+
version_info.get(repo_name, {}).get('VERSION'),
166+
so_title,
167+
logs.get(repo_name))
158168
combined_log_markdown += log_markdown
159169
if not repo_name == "openshot-qt":
160170
formatted_logs[repo_name] = log_title + log_markdown
@@ -167,10 +177,11 @@
167177
github_release_name = "v%s" % version_info.get(repo_name, {}).get('VERSION')
168178
if not releases.get(repo_name):
169179
# Create a new release if one if missing (for each repo)
170-
releases[repo_name] = repos.get(repo_name).create_release(github_release_name,
171-
target_commitish=git_branch_name,
172-
prerelease=True,
173-
body=formatted_logs.get(repo_name))
180+
releases[repo_name] = repos.get(repo_name).create_release(
181+
github_release_name,
182+
target_commitish=git_branch_name,
183+
prerelease=True,
184+
body=formatted_logs.get(repo_name))
174185

175186
# Upload all deploy artifacts/installers to GitHub
176187
# NOTE: ONLY for `openshot-qt` repo
@@ -226,9 +237,11 @@
226237
if line:
227238
shasum_check_output = line.decode('UTF-8').strip()
228239
if shasum_output.split(" ")[0] != shasum_check_output.split(" ")[0]:
229-
raise Exception("shasum validation of %s has failed after downloading "
230-
"the uploaded installer: %s.\n%s\n%s"
231-
% (check_artifact_path, artifact_path, shasum_check_output, shasum_output ))
240+
raise Exception(
241+
"shasum validation of %s has failed after downloading "
242+
"the uploaded installer: %s.\n%s\n%s" % (
243+
check_artifact_path, artifact_path, shasum_check_output, shasum_output)
244+
)
232245

233246
# Create and upload sha2sum file and instructions
234247
output("Hash generated: %s" % shasum_output)
@@ -249,7 +262,19 @@
249262
# Create torrent and upload
250263
torrent_name = "%s.torrent" % artifact_name
251264
torrent_path = os.path.join(artifact_dir, torrent_name)
252-
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"' % (github_release.tag_name, download_url, torrent_name, artifact_name)
265+
tracker_list = [
266+
"udp://tracker.openbittorrent.com:80/announce",
267+
"udp://tracker.publicbt.com:80/announce",
268+
"udp://tracker.opentrackr.org:1337",
269+
]
270+
torrent_command = " ".join([
271+
'mktorrent',
272+
'-a "%s"' % (", ".join(tracker_list)),
273+
'-c "OpenShot Video Editor %s"' % github_release.tag_name,
274+
'-w "%s"' % download_url,
275+
'-o "%s"' % torrent_name,
276+
'"%s"' % artifact_name,
277+
])
253278
torrent_output = ""
254279
for line in run_command(torrent_command, artifact_dir):
255280
output(line)
@@ -265,18 +290,33 @@
265290

266291
# Submit blog post (if it doesn't already exist) (in draft mode)
267292
auth = HTTPBasicAuth(os.getenv('OPENSHOT_ORG_USER'), os.getenv('OPENSHOT_ORG_PASS'))
268-
r = post("https://www.openshot.org/api/release/submit/", auth=auth, data={ "version": openshot_qt_version,
269-
"changelog": log_title + combined_log_markdown })
293+
r = post(
294+
"https://www.openshot.org/api/release/submit/",
295+
auth=auth,
296+
data={
297+
"version": openshot_qt_version,
298+
"changelog": log_title + combined_log_markdown
299+
})
270300
if not r.ok:
271-
raise Exception("HTTP post to openshot.org/api/release/submit/ failed: %s (user: %s): %s" %
272-
(r.status_code, os.getenv('OPENSHOT_ORG_USER'), r.content.decode('UTF-8')))
301+
raise Exception(
302+
"HTTP post to openshot.org/api/release/submit/ failed: %s (user: %s): %s" % (
303+
r.status_code,
304+
os.getenv('OPENSHOT_ORG_USER'),
305+
r.content.decode('UTF-8'))
306+
)
273307
else:
274308
# Publish the release (make new version visible on openshot.org, and make blog post visible)
275309
auth = HTTPBasicAuth(os.getenv('OPENSHOT_ORG_USER'), os.getenv('OPENSHOT_ORG_PASS'))
276-
r = post("https://www.openshot.org/api/release/publish/", auth=auth, data={"version": openshot_qt_version })
310+
r = post(
311+
"https://www.openshot.org/api/release/publish/",
312+
auth=auth,
313+
data={"version": openshot_qt_version})
277314
if not r.ok:
278-
raise Exception("HTTP post to openshot.org/api/release/publish/ failed: %s (user: %s): %s" %
279-
(r.status_code, os.getenv('OPENSHOT_ORG_USER'), r.content.decode('UTF-8')))
315+
raise Exception(
316+
"HTTP post to openshot.org/api/release/publish/ failed: %s (user: %s): %s" % (
317+
r.status_code,
318+
os.getenv('OPENSHOT_ORG_USER'),
319+
r.content.decode('UTF-8')))
280320

281321
# Publish GitHub Release objects (in all 3 repos)
282322
for repo_name in repo_names:
@@ -286,8 +326,10 @@
286326
# Publish github release also
287327
github_release.edit(prerelease=False)
288328
else:
289-
raise Exception("Cannot publish missing GitHub release: %s, version: %s" %
290-
(repo_name, openshot_qt_version))
329+
raise Exception(
330+
"Cannot publish missing GitHub release: %s, version: %s" % (
331+
repo_name,
332+
openshot_qt_version))
291333

292334
# Verify download links on openshot.org are correct (and include the new release version)
293335
r = get("https://www.openshot.org/download/")
@@ -300,28 +342,43 @@
300342
if r.ok and r.reason == "Found":
301343
output("Validation of URL successful: %s" % url)
302344
else:
303-
raise Exception("Validation of URL FAILED: %s, %s, %s" % (url, r.status_code, r.reason))
345+
raise Exception(
346+
"Validation of URL FAILED: %s, %s, %s" % (
347+
url, r.status_code, r.reason)
348+
)
304349

305350
# Validate the current version is found in each URL
306351
if openshot_qt_version not in url:
307-
raise Exception("Validation of URL FAILED. Missing version %s: %s, %s, %s" %
308-
(openshot_qt_version, url,
309-
r.status_code, r.reason))
352+
raise Exception(
353+
"Validation of URL FAILED. Missing version %s: %s, %s, %s" % (
354+
openshot_qt_version,
355+
url,
356+
r.status_code,
357+
r.reason)
358+
)
310359
else:
311-
raise Exception("Failed to GET openshot.org/download for URL validation: %s" % r.status_code)
360+
raise Exception(
361+
"Failed to GET openshot.org/download for URL validation: %s" % r.status_code)
312362

313363
except Exception as ex:
314364
tb = traceback.format_exc()
315365
error("Unhandled %s exception: %s - %s" % (script_mode, str(ex), str(tb)))
316366

317367
if not errors_detected:
318368
output("Successfully completed %s script!" % script_mode)
319-
zulip_upload_log(zulip_token, log,
320-
"%s: %s **success** log" % (platform.system(), script_mode),
321-
":congratulations: successful %s" % script_mode)
369+
zulip_upload_log(
370+
zulip_token, log,
371+
"%s: %s **success** log" % (platform.system(), script_mode),
372+
":congratulations: successful %s" % script_mode)
322373
else:
323374
# Report any errors detected
324375
output("%s script failed!" % script_mode)
325-
zulip_upload_log(zulip_token, log, "%s: %s error log" % (platform.system(), script_mode),
326-
":skull_and_crossbones: %s" % truncate(errors_detected[0], 100))
376+
zulip_upload_log(
377+
zulip_token, log,
378+
"%s: %s error log" % (platform.system(), script_mode),
379+
":skull_and_crossbones: %s" % truncate(errors_detected[0], 100))
327380
exit(1)
381+
382+
383+
if __name__ == "__main__":
384+
main()

0 commit comments

Comments
 (0)