diff options
author | Harry Youd <harry@harryyoud.co.uk> | 2017-05-19 20:40:14 +0100 |
---|---|---|
committer | Harry Youd <harry@harryyoud.co.uk> | 2017-05-20 13:47:20 +0000 |
commit | 398cf1046e65d190578784876e200c29ca7855f9 (patch) | |
tree | 8ac255dc661319d762b343a55635f2f8f6c11b26 /device-deps-regenerator/app.py | |
parent | f0ab2a92ae9bad668c58509b6ad2437625fabf95 (diff) | |
download | scripts-398cf1046e65d190578784876e200c29ca7855f9.tar.gz scripts-398cf1046e65d190578784876e200c29ca7855f9.tar.bz2 scripts-398cf1046e65d190578784876e200c29ca7855f9.zip |
Change to dashes to keep inline with maintainers folder
Change-Id: Id49a330106377997ebbeb2d56ed4c623c9f1e978
Diffstat (limited to 'device-deps-regenerator/app.py')
-rw-r--r-- | device-deps-regenerator/app.py | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/device-deps-regenerator/app.py b/device-deps-regenerator/app.py new file mode 100644 index 0000000..a39985b --- /dev/null +++ b/device-deps-regenerator/app.py @@ -0,0 +1,126 @@ +import concurrent.futures +import github +import json +import traceback + +from github import Github +from base64 import b64decode + +with open('token') as f: + g = Github(f.readline().strip(), per_page=200) + + +print(g.rate_limiting_resettime) + +org = g.get_organization('LineageOS') + +# supported branches, newest to oldest +CUR_BRANCHES = ['cm-14.1', 'cm-13.0'] + +def get_cm_dependencies(repo): + branch = None + for b in CUR_BRANCHES: + try: + branch = repo.get_branch(b) + break + except github.GithubException: + continue + + if branch is None: + return None + + sha = branch.commit.sha + try: + tree = repo.get_git_tree(sha) + except github.GithubException: + return None + blob_sha = None + for el in tree.tree: + if el.path == 'cm.dependencies' or el.path == 'lineage.dependencies': + blob_sha = el.sha + break + + if blob_sha is None: + return [[], set()] + + blob = repo.get_git_blob(blob_sha) + + deps = b64decode(blob.content) + + 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}) + + return [mydeps, non_device_repos] + +futures = {} +n = 1 + +dependencies = {} +other_repos = set() + + +with concurrent.futures.ThreadPoolExecutor() as executor: + for repo in g.get_organization('LineageOS').get_repos(): + if '_device_' not in repo.name: + continue + print(n, repo.name) + n += 1 + futures[executor.submit(get_cm_dependencies, repo)] = repo.name + for future in concurrent.futures.as_completed(futures): + name = futures[future] + try: + data = future.result() + if data is None: + continue + dependencies[name] = data[0] + other_repos.update(data[1]) + print(name, "=>", data[0]) + except Exception as e: + print('%r generated an exception: %s'%(name, e)) + traceback.print_exc() + continue + futures = {} + + print(other_repos) + for name in other_repos: + print(name) + try: + repo = org.get_repo(name) + futures[executor.submit(get_cm_dependencies, repo)] = name + except Exception: + continue + + other_repos = {} + for future in concurrent.futures.as_completed(futures): + name = futures[future] + try: + data = future.result() + if data is None: + continue + dependencies[name] = data[0] + for el in data[1]: + if el in dependencies: + continue + other_repos.update(data[1]) + print(name, "=>", data[0]) + except Exception as e: + print('%r generated an exception: %s'%(name, e)) + traceback.print_exc() + continue + futures = {} + + +print(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: + json.dump(dependencies, f, indent=4) |