nix: remove unused code from update.py
This commit is contained in:
parent
2bada04b9d
commit
48dfd73c91
@ -2,23 +2,18 @@
|
|||||||
|
|
||||||
# Update the Nix package pin
|
# Update the Nix package pin
|
||||||
#
|
#
|
||||||
# Usage: ./update.sh [PATH]
|
# Usage: ./update.sh
|
||||||
# When the [PATH] is not set, it will fetch the latest release from the repo.
|
|
||||||
# With [PATH] set, it will hash the given file and generate the URL,
|
|
||||||
# base on the version contained within the file
|
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
import sys
|
import sys
|
||||||
import re
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
OUTPUT_FILE = Path("pin.json")
|
OUTPUT_FILE = Path("pin.json")
|
||||||
TARGET_ASSET = lambda version: f"copyparty-{version}.tar.gz"
|
TARGET_ASSET = lambda version: f"copyparty-{version}.tar.gz"
|
||||||
HASH_TYPE = "sha256"
|
HASH_TYPE = "sha256"
|
||||||
LATEST_RELEASE_URL = "https://api.github.com/repos/9001/copyparty/releases/latest"
|
LATEST_RELEASE_URL = "https://api.github.com/repos/9001/copyparty/releases/latest"
|
||||||
DOWNLOAD_URL = lambda version: f"https://github.com/9001/copyparty/releases/download/v{version}/{TARGET_ASSET}"
|
|
||||||
|
|
||||||
|
|
||||||
def get_formatted_hash(binary):
|
def get_formatted_hash(binary):
|
||||||
@ -29,14 +24,6 @@ def get_formatted_hash(binary):
|
|||||||
return f"{HASH_TYPE}-{encoded_hash}"
|
return f"{HASH_TYPE}-{encoded_hash}"
|
||||||
|
|
||||||
|
|
||||||
def version_from_sfx(binary):
|
|
||||||
result = re.search(b'^VER = "(.*)"$', binary, re.MULTILINE)
|
|
||||||
if result:
|
|
||||||
return result.groups(1)[0].decode("ascii")
|
|
||||||
|
|
||||||
raise ValueError("version not found in provided file")
|
|
||||||
|
|
||||||
|
|
||||||
def remote_release_pin():
|
def remote_release_pin():
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@ -51,21 +38,7 @@ def remote_release_pin():
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def local_release_pin(path):
|
|
||||||
asset = path.read_bytes()
|
|
||||||
version = version_from_sfx(asset)
|
|
||||||
download_url = DOWNLOAD_URL(version)
|
|
||||||
formatted_hash = get_formatted_hash(asset)
|
|
||||||
|
|
||||||
result = {"url": download_url, "version": version, "hash": formatted_hash}
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) > 1:
|
|
||||||
asset_path = Path(sys.argv[1])
|
|
||||||
result = local_release_pin(asset_path)
|
|
||||||
else:
|
|
||||||
result = remote_release_pin()
|
result = remote_release_pin()
|
||||||
|
|
||||||
print(result)
|
print(result)
|
||||||
|
Loading…
Reference in New Issue
Block a user