Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions gen_data/gen-update-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,26 @@
import arch

GIT_ROOT = os.popen("git rev-parse --show-toplevel").read().strip()
DIR = "fs-cook/out"
DIR = "."
VERBOSE = False
JSON_CONF = f"{GIT_ROOT}/distro-data.json"

def update_json_conf(file) -> None:
data = strip_info(file)
jdata = json.load(open(JSON_CONF, 'r'))

# resolv data
jdata = utils.resolv_data(jdata, data[0], data[1], [data[2]])

# update url
jdata[data[0]][data[1]][f"{data[2]}url"] = get_release_url(
RELEASE_TAG, data[3])
jdata[data[0]] \
[data[1]] \
[f"{data[2]}url"] = get_release_url(RELEASE_TAG, data[3])

# update sha
jdata[data[0]][data[1]][f"{data[2]}sha"] = os.popen(
f"sha256sum {DIR}/{data[3]}").read().split()[0]
jdata[data[0]] \
[data[1]] \
[f"{data[2]}sha"] = os.popen(f"sha256sum {file}").read().split()[0]

# update JSON_CONF
file = open(JSON_CONF, 'w')
Expand All @@ -31,7 +36,7 @@ def strip_info(file):
name = os.path.splitext(name)[0]

sp = name.split("-")
StoPdict = arch.translate()
StoPdict = arch.translated_arch()

suite = sp[0]
variant = sp[1]
Expand All @@ -40,8 +45,8 @@ def strip_info(file):
return [suite, variant, packageArchitecture, basename]

def get_release_url(release_tag, file) -> str:
repo="https://github.com/RandomCoderOrg/udroid-download"
url="{}/releases/download/{}/{}".format(repo, release_tag, file)
repo ="https://github.com/RandomCoderOrg/udroid-download"
url ="{}/releases/download/{}/{}".format(repo, release_tag, file)
return url

if __name__ == '__main__':
Expand All @@ -54,8 +59,10 @@ def get_release_url(release_tag, file) -> str:
options, args = parser.parse_args()
# get release tag

from utils import getfilesR

RELEASE_TAG = options.release_tag
for file in os.listdir(DIR):
for file in getfilesR(DIR):
if file.endswith(".tar.gz"):
update_json_conf(file)

28 changes: 23 additions & 5 deletions gen_data/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import json
import arch as archAlt
archAltName = archAlt.ReverseTranslate()
import os

def add_suite(JsonFile: dict, suite: str) -> None:
""" Add suite to the JsonFile
Expand Down Expand Up @@ -37,6 +35,9 @@ def add_arch(JsonFile: dict, suite: str, varient: str, arch:list[str]) -> None:
arch (list[str]): The arch to add
"""

import arch as archAlt
archAltName = archAlt.ReverseTranslate()

#revArchLst = {'armhf': ['armhf', 'arm'], 'aarch64': ['arm64', 'aarch64'], 'amd64': ['amd64', 'x86_64']}
revArchLst = archAltName[arch]
for revArch in revArchLst:
Expand All @@ -53,14 +54,31 @@ def resolv_data(
Name: str = ...,
FriendlyName: str = ...,
) -> dict:

if Name is ...:
Name = f"{suite}-{variant}"

if FriendlyName is ...:
FriendlyName = f"{suite} {variant}"

if suite not in json_data["suites"]:
add_suite(json_data,suite)

if variant not in json_data[suite]["varients"]:
add_varient(json_data, suite, variant, Name, FriendlyName)

for arc in arch:
if arch not in json_data[suite][variant]["arch"]:
if arc not in json_data[suite][variant]["arch"]:
add_arch(json_data, suite, variant, arc)

return json_data
return json_data

def getfilesR(path: str) -> list:

files = []
# include depth
for r, d, f in os.walk(path):
for file in f:
files.append(os.path.join(r, file))

return files