device-deps-regenerator: Reformat with black

Change-Id: Ib17eee1dabda4cf126e5a4e6143c23d96d5c6042
This commit is contained in:
LuK1337
2023-04-01 23:28:49 +02:00
parent 1041ba523b
commit 64a443d7ed
3 changed files with 74 additions and 52 deletions

View File

@@ -8,19 +8,22 @@ from github import Github
from base64 import b64decode
parser = argparse.ArgumentParser()
parser.add_argument('-j', '--jobs', type=int, help='Max number of workers to use. Default is none')
parser.add_argument(
"-j", "--jobs", type=int, help="Max number of workers to use. Default is none"
)
args = parser.parse_args()
with open('token') as f:
with open("token") as f:
g = Github(f.readline().strip(), per_page=200)
print(g.rate_limiting_resettime)
org = g.get_organization('LineageOS')
org = g.get_organization("LineageOS")
# supported branches, newest to oldest
CUR_BRANCHES = ['lineage-20', 'lineage-20.0', 'lineage-19.1', 'lineage-18.1']
CUR_BRANCHES = ["lineage-20", "lineage-20.0", "lineage-19.1", "lineage-18.1"]
def get_cm_dependencies(repo):
branch = None
@@ -41,7 +44,7 @@ def get_cm_dependencies(repo):
return None
blob_sha = None
for el in tree.tree:
if el.path == 'lineage.dependencies':
if el.path == "lineage.dependencies":
blob_sha = el.sha
break
@@ -52,18 +55,19 @@ def get_cm_dependencies(repo):
deps = b64decode(blob.content)
cmdeps = json.loads(deps.decode('utf-8'))
cmdeps = json.loads(deps.decode("utf-8"))
mydeps = []
non_device_repos = set()
for el in cmdeps:
if '_device_' not in el['repository']:
non_device_repos.add(el['repository'])
depbranch = el.get('branch', branch.name)
mydeps.append({'repo': el['repository'], 'branch': depbranch})
if "_device_" not in el["repository"]:
non_device_repos.add(el["repository"])
depbranch = el.get("branch", branch.name)
mydeps.append({"repo": el["repository"], "branch": depbranch})
return [mydeps, non_device_repos]
futures = {}
n = 1
@@ -71,8 +75,8 @@ dependencies = {}
other_repos = set()
with concurrent.futures.ThreadPoolExecutor(max_workers=args.jobs) as executor:
for repo in g.get_organization('LineageOS').get_repos():
if '_device_' not in repo.name and '_hardware_' not in repo.name:
for repo in g.get_organization("LineageOS").get_repos():
if "_device_" not in repo.name and "_hardware_" not in repo.name:
continue
print(n, repo.name)
n += 1
@@ -87,7 +91,7 @@ with concurrent.futures.ThreadPoolExecutor(max_workers=args.jobs) as executor:
other_repos.update(data[1])
print(name, "=>", data[0])
except Exception as e:
print('%r generated an exception: %s'%(name, e))
print("%r generated an exception: %s" % (name, e))
traceback.print_exc()
continue
futures = {}
@@ -115,16 +119,16 @@ with concurrent.futures.ThreadPoolExecutor(max_workers=args.jobs) as executor:
other_repos.update(data[1])
print(name, "=>", data[0])
except Exception as e:
print('%r generated an exception: %s'%(name, e))
print("%r generated an exception: %s" % (name, e))
traceback.print_exc()
continue
futures = {}
print(other_repos)
#for name in other_repos:
# for name in other_repos:
# repo = org.get_repo(name)
# dependencies[name] = get_cm_dependencies(repo)
with open('out.json', 'w') as f:
with open("out.json", "w") as f:
json.dump(dependencies, f, indent=4)

View File

@@ -4,16 +4,16 @@ import json
# otherwise the script will remove these on the assumption
# they are common repos
COMMON_DEVICE = [
'android_device_asus_flo',
'android_device_asus_grouper',
'android_device_google_marlin',
'android_device_htc_flounder',
'android_device_samsung_espressowifi',
'android_device_samsung_n1awifi',
'android_device_samsung_t0lte',
"android_device_asus_flo",
"android_device_asus_grouper",
"android_device_google_marlin",
"android_device_htc_flounder",
"android_device_samsung_espressowifi",
"android_device_samsung_n1awifi",
"android_device_samsung_t0lte",
]
with open('out.json') as f:
with open("out.json") as f:
mapping = json.load(f)
kernels = {}
@@ -25,13 +25,16 @@ for device in mapping:
if device not in reverse_deps:
reverse_deps[device] = []
for repo in deps:
if repo['repo'] not in reverse_deps:
reverse_deps[repo['repo']] = []
reverse_deps[repo['repo']].append(device)
if repo["repo"] not in reverse_deps:
reverse_deps[repo["repo"]] = []
reverse_deps[repo["repo"]].append(device)
def simplify_reverse_deps(repo):
if len(reverse_deps[repo]) == 0 and '-common' not in repo:
return {repo,}
if len(reverse_deps[repo]) == 0 and "-common" not in repo:
return {
repo,
}
res = set()
for i in reverse_deps[repo]:
res.update(simplify_reverse_deps(i))
@@ -39,9 +42,10 @@ def simplify_reverse_deps(repo):
res.add(repo)
return res
for repo in reverse_deps:
if 'kernel' in repo:
if "kernel" in repo:
kernels[repo] = sorted(list(simplify_reverse_deps(repo)))
with open('kernels.json', 'w') as f:
with open("kernels.json", "w") as f:
json.dump(kernels, f, indent=4, sort_keys=True)

View File

@@ -1,37 +1,51 @@
import json
with open('out.json') as f:
with open("out.json") as f:
mapping = json.load(f)
devices = {}
suffixes = {}
ignorelist = ['sepolicy', 'devicesettings', 'common', 'atv', 'redbull', 'raviole', 'gs101', 'pantah', 'gs201']
ignorelist = [
"sepolicy",
"devicesettings",
"common",
"atv",
"redbull",
"raviole",
"gs101",
"pantah",
"gs201",
]
def simplify_reverse_deps(repo, device):
# repo['branch'] = cm-14.1 or cm-14.1-caf or cm-14.1-sony
if 'branch' in repo and repo['branch'].count('-') > 1: # get suffix
if repo['repo'] not in suffixes:
suffixes[repo['repo']] = {}
suffixes[repo['repo']][device] = '-' + repo['branch'].split('-', 2)[2]
if "branch" in repo and repo["branch"].count("-") > 1: # get suffix
if repo["repo"] not in suffixes:
suffixes[repo["repo"]] = {}
suffixes[repo["repo"]][device] = "-" + repo["branch"].split("-", 2)[2]
if repo['repo'] not in mapping or len(mapping[repo['repo']]) == 0:
return [repo['repo']]
if repo["repo"] not in mapping or len(mapping[repo["repo"]]) == 0:
return [repo["repo"]]
res = []
for i in mapping[repo['repo']]:
res += (simplify_reverse_deps(i, device))
res.append(repo['repo'])
for i in mapping[repo["repo"]]:
res += simplify_reverse_deps(i, device)
res.append(repo["repo"])
return res
for repo in mapping:
if 'device' not in repo or any(x in repo for x in ignorelist):
continue
codename = repo.split('_', maxsplit=3)[-1]
if codename in devices:
print("warning: dupe: %s"%codename)
devices[codename] = sorted(list(set(simplify_reverse_deps({'repo': repo}, codename))))
with open('device_deps.json', 'w') as f:
out = {'devices': devices, 'suffixes': suffixes}
for repo in mapping:
if "device" not in repo or any(x in repo for x in ignorelist):
continue
codename = repo.split("_", maxsplit=3)[-1]
if codename in devices:
print("warning: dupe: %s" % codename)
devices[codename] = sorted(
list(set(simplify_reverse_deps({"repo": repo}, codename)))
)
with open("device_deps.json", "w") as f:
out = {"devices": devices, "suffixes": suffixes}
out = devices
json.dump(out, f, indent=4, sort_keys=True)
f.write('\n')
f.write("\n")