|
| 1 | +import os |
| 2 | +import json |
| 3 | +import optparse |
| 4 | + |
| 5 | +GIT_ROOT = os.popen("git rev-parse --show-toplevel").read().strip() |
| 6 | +DIR = "." |
| 7 | +VERBOSE = False |
| 8 | +JSON_CONF = f"{GIT_ROOT}/distro-data.json" |
| 9 | + |
| 10 | +def update_json_conf(file) -> None: |
| 11 | + data = strip_info(file) |
| 12 | + jdata = json.load(open(JSON_CONF, 'r')) |
| 13 | + |
| 14 | + # update url |
| 15 | + jdata[data[0]][data[1]][f"{data[2]}Url"] = get_release_url( |
| 16 | + RELEASE_TAG, data[3]) |
| 17 | + |
| 18 | + # update sha |
| 19 | + jdata[data[0]][data[1]][f"{data[2]}sha"] = os.popen( |
| 20 | + f"sha256sum {DIR}/{data[3]}").read().split()[0] |
| 21 | + |
| 22 | + # update JSON_CONF |
| 23 | + file = open(JSON_CONF, 'w') |
| 24 | + json.dump(jdata, file, indent=4) |
| 25 | + |
| 26 | + |
| 27 | +def strip_info(file): |
| 28 | + basename = os.path.basename(file) |
| 29 | + name = os.path.splitext(basename)[0] |
| 30 | + name = os.path.splitext(name)[0] |
| 31 | + |
| 32 | + sp = name.split("-") |
| 33 | + ar = { |
| 34 | + "armhf": "armhf", |
| 35 | + "arm": "armhf", |
| 36 | + "arm64": "aarch64", |
| 37 | + "aarch64": "aarch64", |
| 38 | + "amd64": "amd64", |
| 39 | + "x86_64": "amd64" |
| 40 | + } |
| 41 | + |
| 42 | + suite = sp[0] |
| 43 | + variant = sp[1] |
| 44 | + arch = ar[sp[2]] |
| 45 | + |
| 46 | + return [suite, variant, arch, basename] |
| 47 | + |
| 48 | +def get_release_url(release_tag, file) -> str: |
| 49 | + repo="https://github.com/RandomCoderOrg/udroid-download" |
| 50 | + url="{}/releases/download/{}/{}".format(repo, release_tag, file) |
| 51 | + return url |
| 52 | + |
| 53 | +if __name__ == '__main__': |
| 54 | + # parse command line options |
| 55 | + parser = optparse.OptionParser() |
| 56 | + |
| 57 | + parser.add_option('-R', '--release-tag', dest='release_tag', |
| 58 | + help='release tag', type=str) |
| 59 | + |
| 60 | + options, args = parser.parse_args() |
| 61 | + # get release tag |
| 62 | + |
| 63 | + RELEASE_TAG = options.release_tag |
| 64 | + for file in os.listdir(DIR): |
| 65 | + if file.endswith(".tar.gz"): |
| 66 | + update_json_conf(file) |
| 67 | + |
0 commit comments