gnomeExtensions: update-extensions.py improve download

This commit is contained in:
Ryan Horiguchi 2022-04-23 01:24:38 +02:00
parent 51fdb8f239
commit dcb93d0080
No known key found for this signature in database
GPG key ID: CA7EE98D45A1132A

View file

@ -2,13 +2,11 @@
#!nix-shell -I nixpkgs=../../../.. -i python3 -p python3 #!nix-shell -I nixpkgs=../../../.. -i python3 -p python3
import base64 import base64
import io
import json import json
import logging import logging
import subprocess import subprocess
import urllib.error import urllib.error
import urllib.request import urllib.request
import zipfile
from operator import itemgetter from operator import itemgetter
from pathlib import Path from pathlib import Path
from typing import List, Dict, Optional, Any, Tuple from typing import List, Dict, Optional, Any, Tuple
@ -53,22 +51,29 @@ def fetch_extension_data(uuid: str, version: str) -> Tuple[str, str]:
if url == 'https://extensions.gnome.org/extension-data/VitalsCoreCoding.com.v53.shell-extension.zip': if url == 'https://extensions.gnome.org/extension-data/VitalsCoreCoding.com.v53.shell-extension.zip':
url = 'https://extensions.gnome.org/extension-data/VitalsCoreCoding.com.v53.shell-extension_v1BI2FB.zip' url = 'https://extensions.gnome.org/extension-data/VitalsCoreCoding.com.v53.shell-extension_v1BI2FB.zip'
# Yes, we download that file three times: # Yes, we download that file two times:
# The first time is for the maintainer, so they may have a personal backup to fix potential issues # The first time is for the maintainer, so they may have a personal backup to fix potential issues
# subprocess.run( # subprocess.run(
# ["wget", url], capture_output=True, text=True # ["wget", url], capture_output=True, text=True
# ) # )
# The second time, we extract the metadata.json because we need it too # The second time, we add the file to store
with urllib.request.urlopen(url) as response: process = subprocess.run(
data = zipfile.ZipFile(io.BytesIO(response.read()), 'r') ["nix-prefetch-url", "--unpack", "--print-path", url], capture_output=True, text=True
metadata = base64.b64encode(data.read('metadata.json')).decode() )
# The third time is to get the file into the store and to get its hash lines = process.stdout.splitlines()
hash = subprocess.run(
["nix-prefetch-url", "--unpack", url], capture_output=True, text=True # Get hash from first line of nix-prefetch-url output
).stdout.strip() hash = lines[0].strip()
# Get path from second line of nix-prefetch-url output
path = Path(lines[1].strip())
# Get metadata.json content from nix-store
with open(path / "metadata.json", "r") as out:
metadata = base64.b64encode(out.read().encode("ascii")).decode()
return hash, metadata return hash, metadata