[epiphany] generate-canary-manifest: Remove dependency on requests



commit 6c3aec7349b5a1de606ec72f82526146e2d1d2b0
Author: Philippe Normand <phil base-art net>
Date:   Mon Oct 18 21:25:45 2021 +0100

    generate-canary-manifest: Remove dependency on requests
    
    Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1024>

 .gitlab-ci.yml              |  1 -
 generate-canary-manifest.py | 27 +++++++++------------------
 2 files changed, 9 insertions(+), 19 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 568e49cab..5cd798bf8 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -79,7 +79,6 @@ canary:
     SDK_REPO: 'https://software.igalia.com/flatpak-refs/webkit-sdk.flatpakrepo'
     BUNDLE: 'epiphany-canary.flatpak'
   script:
-    - pip3 install --user requests
     # TODO: Switch to debug? 5GB downloads though.
     - python generate-canary-manifest.py --release
     - flatpak remote-add --user --if-not-exists webkit-sdk ${SDK_REPO}
diff --git a/generate-canary-manifest.py b/generate-canary-manifest.py
index 1e62ea819..a02edd368 100644
--- a/generate-canary-manifest.py
+++ b/generate-canary-manifest.py
@@ -24,7 +24,6 @@ import os
 import re
 import sys
 import urllib.request
-import requests
 
 ZIP_FILE = "webkitgtk.zip"
 
@@ -52,24 +51,16 @@ def download_zipped_build(build_type):
     print(f"Downloading build {latest} from {url}")
     zip_file = open(ZIP_FILE, "wb")
 
-    # https://sumit-ghosh.com/articles/python-download-progress-bar/
-    response = requests.get(f"{url}/{latest}", stream=True)
-    total = response.headers.get('content-length')
+    def update(blocks, bs, size):
+        done = int(50 * blocks * bs / size)
+        sys.stdout.write('\r[{}{}]'.format('█' * done, '.' * (50 - done)))
+        sys.stdout.flush()
+
+    urllib.request.urlretrieve(f"{url}/{latest}", ZIP_FILE, update)
     h = hashlib.new('sha256')
-    if total is None:
-        h.update(response.content)
-        zip_file.write(response.content)
-    else:
-        downloaded = 0
-        total = int(total)
-        for data in response.iter_content(chunk_size=max(int(total / 1000), 1024 * 1024)):
-            downloaded += len(data)
-            h.update(data)
-            zip_file.write(data)
-            done = int(50 * downloaded / total)
-            sys.stdout.write('\r[{}{}]'.format('█' * done, '.' * (50 - done)))
-            sys.stdout.flush()
-    sys.stdout.write('\n')
+    with open(ZIP_FILE, "rb") as f:
+        h.update(f.read())
+
     checksum = h.hexdigest()
     return (ZIP_FILE, checksum)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]