Title: [228396] trunk/Tools
Revision
228396
Author
ross.kirsl...@sony.com
Date
2018-02-12 14:37:57 -0800 (Mon, 12 Feb 2018)

Log Message

download-latest-github-release .py should not use "browser download URL".
https://bugs.webkit.org/show_bug.cgi?id=182646

Reviewed by Per Arne Vollan.

* Scripts/download-latest-github-release.py:
Download request should be a proper GitHub API call and should actually include the token when applicable.
(Also clean up usage of args and print while we're in here.)

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (228395 => 228396)


--- trunk/Tools/ChangeLog	2018-02-12 22:34:16 UTC (rev 228395)
+++ trunk/Tools/ChangeLog	2018-02-12 22:37:57 UTC (rev 228396)
@@ -1,3 +1,14 @@
+2018-02-12  Ross Kirsling  <ross.kirsl...@sony.com>
+
+        download-latest-github-release .py should not use "browser download URL".
+        https://bugs.webkit.org/show_bug.cgi?id=182646
+
+        Reviewed by Per Arne Vollan.
+
+        * Scripts/download-latest-github-release.py:
+        Download request should be a proper GitHub API call and should actually include the token when applicable.
+        (Also clean up usage of args and print while we're in here.)
+
 2018-02-12  Per Arne Vollan  <pvol...@apple.com>
 
         EWS should run Windows tests.

Modified: trunk/Tools/Scripts/download-latest-github-release.py (228395 => 228396)


--- trunk/Tools/Scripts/download-latest-github-release.py	2018-02-12 22:34:16 UTC (rev 228395)
+++ trunk/Tools/Scripts/download-latest-github-release.py	2018-02-12 22:37:57 UTC (rev 228396)
@@ -59,13 +59,13 @@
     return parser.parse_args(argv)
 
 
-def find_latest_release(args):
-    url = ''.format(args.endpoint.rstrip('/'), args.repo)
+def find_latest_release(endpoint, repo, filename, token):
+    url = ''.format(endpoint.rstrip('/'), repo)
 
     request = urllib2.Request(url)
     request.add_header('Accept', 'application/vnd.github.v3+json')
-    if args.token:
-        request.add_header('Authorization', 'token {}'.format(args.token))
+    if token:
+        request.add_header('Authorization', 'token {}'.format(token))
 
     try:
         response = urllib2.urlopen(request)
@@ -75,15 +75,20 @@
 
     data = ""
     for asset in data['assets']:
-        if asset['name'] == args.filename:
+        if asset['name'] == filename:
             version_info = {'tag_name': data['tag_name'], 'updated_at': asset['updated_at']}
-            return asset['browser_download_url'], version_info
+            return asset['url'], version_info
     return None, None
 
 
-def download_release(source_url, target_path):
+def download_release(source_url, target_path, token):
+    request = urllib2.Request(source_url)
+    request.add_header('Accept', 'application/octet-stream')
+    if token:
+        request.add_header('Authorization', 'token {}'.format(token))
+
     with open(target_path, 'wb') as file:
-        file.write(urllib2.urlopen(source_url).read())
+        file.write(urllib2.urlopen(request).read())
 
 
 def load_version_info(version_info_path):
@@ -109,12 +114,12 @@
 
     existing_version_info = load_version_info(version_info_path)
     if existing_version_info:
-        print('Found existing release:', existing_version_info['tag_name'])
+        print('Found existing release: {}'.format(existing_version_info['tag_name']))
     else:
         print('No existing release found.')
 
     print('Seeking latest release from {}...'.format(args.repo))
-    release_url, latest_version_info = find_latest_release(args)
+    release_url, latest_version_info = find_latest_release(args.endpoint, args.repo, args.filename, args.token)
 
     if not latest_version_info:
         if existing_version_info:
@@ -124,7 +129,7 @@
         print('No release found!')
         return Status.COULD_NOT_FIND
 
-    print('Found latest release:', latest_version_info['tag_name'])
+    print('Found latest release: {}'.format(latest_version_info['tag_name']))
 
     if latest_version_info == existing_version_info:
         print('Already up-to-date!')
@@ -134,7 +139,7 @@
         os.makedirs(args.output_dir)
 
     print('Downloading to {}...'.format(os.path.abspath(args.output_dir)))
-    download_release(release_url, binary_path)
+    download_release(release_url, binary_path, args.token)
     save_version_info(version_info_path, latest_version_info)
     print('Done!')
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to