|
50 | 50 | urllib3.disable_warnings()
|
51 | 51 |
|
52 | 52 |
|
53 |
| -if __name__ == "__main__": |
| 53 | +def main(): |
54 | 54 | # Only run this code when directly executing this script.
|
55 | 55 |
|
56 | 56 | zulip_token = None
|
|
82 | 82 | script_mode = "publish"
|
83 | 83 |
|
84 | 84 | # 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"))) |
87 | 89 |
|
88 | 90 | # Detect artifact folder (if any)
|
89 | 91 | artifact_dir = os.path.join(PATH, "build")
|
90 | 92 |
|
91 | 93 | # Parse artifact version files (if found)
|
92 | 94 | 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))) |
94 | 97 | output(str(version_info))
|
95 | 98 |
|
96 | 99 | # Get version info
|
|
104 | 107 | original_git_branch = git_branch_name
|
105 | 108 | if original_git_branch != git_branch_name:
|
106 | 109 | # 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)) |
109 | 113 |
|
110 | 114 | # Loop through and get and/or create the GitHub Release objects
|
111 | 115 | releases = {}
|
|
122 | 126 | # Get official version release (i.e. v2.1.0, v2.x.x)
|
123 | 127 | releases[repo_name] = get_release(repos.get(repo_name), github_release_name)
|
124 | 128 | 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 | + ) |
128 | 135 | else:
|
129 | 136 | # 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)) |
133 | 141 |
|
134 | 142 | if not is_publish:
|
135 | 143 |
|
|
152 | 160 | so_title = ""
|
153 | 161 | if so_number:
|
154 | 162 | 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)) |
158 | 168 | combined_log_markdown += log_markdown
|
159 | 169 | if not repo_name == "openshot-qt":
|
160 | 170 | formatted_logs[repo_name] = log_title + log_markdown
|
|
167 | 177 | github_release_name = "v%s" % version_info.get(repo_name, {}).get('VERSION')
|
168 | 178 | if not releases.get(repo_name):
|
169 | 179 | # 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)) |
174 | 185 |
|
175 | 186 | # Upload all deploy artifacts/installers to GitHub
|
176 | 187 | # NOTE: ONLY for `openshot-qt` repo
|
|
226 | 237 | if line:
|
227 | 238 | shasum_check_output = line.decode('UTF-8').strip()
|
228 | 239 | 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 | + ) |
232 | 245 |
|
233 | 246 | # Create and upload sha2sum file and instructions
|
234 | 247 | output("Hash generated: %s" % shasum_output)
|
|
249 | 262 | # Create torrent and upload
|
250 | 263 | torrent_name = "%s.torrent" % artifact_name
|
251 | 264 | 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 | + ]) |
253 | 278 | torrent_output = ""
|
254 | 279 | for line in run_command(torrent_command, artifact_dir):
|
255 | 280 | output(line)
|
|
265 | 290 |
|
266 | 291 | # Submit blog post (if it doesn't already exist) (in draft mode)
|
267 | 292 | 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 | + }) |
270 | 300 | 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 | + ) |
273 | 307 | else:
|
274 | 308 | # Publish the release (make new version visible on openshot.org, and make blog post visible)
|
275 | 309 | 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}) |
277 | 314 | 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'))) |
280 | 320 |
|
281 | 321 | # Publish GitHub Release objects (in all 3 repos)
|
282 | 322 | for repo_name in repo_names:
|
|
286 | 326 | # Publish github release also
|
287 | 327 | github_release.edit(prerelease=False)
|
288 | 328 | 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)) |
291 | 333 |
|
292 | 334 | # Verify download links on openshot.org are correct (and include the new release version)
|
293 | 335 | r = get("https://www.openshot.org/download/")
|
|
300 | 342 | if r.ok and r.reason == "Found":
|
301 | 343 | output("Validation of URL successful: %s" % url)
|
302 | 344 | 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 | + ) |
304 | 349 |
|
305 | 350 | # Validate the current version is found in each URL
|
306 | 351 | 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 | + ) |
310 | 359 | 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) |
312 | 362 |
|
313 | 363 | except Exception as ex:
|
314 | 364 | tb = traceback.format_exc()
|
315 | 365 | error("Unhandled %s exception: %s - %s" % (script_mode, str(ex), str(tb)))
|
316 | 366 |
|
317 | 367 | if not errors_detected:
|
318 | 368 | 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) |
322 | 373 | else:
|
323 | 374 | # Report any errors detected
|
324 | 375 | 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)) |
327 | 380 | exit(1)
|
| 381 | + |
| 382 | + |
| 383 | +if __name__ == "__main__": |
| 384 | + main() |
0 commit comments