From 9b72030419d8814ac0c93fc54e1150931a9fc5d6 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 5 Apr 2020 03:27:44 +0200 Subject: [PATCH] More comments --- list_builder.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/list_builder.py b/list_builder.py index 9e2a0718..d0bcd0f2 100755 --- a/list_builder.py +++ b/list_builder.py @@ -17,10 +17,22 @@ my_env["GIT_TERMINAL_PROMPT"] = "0" os.makedirs(".apps_cache", exist_ok=True) os.makedirs("builds/", exist_ok=True) +################################### +# App git clones cache management # +################################### + def app_cache_folder(app): return os.path.join(".apps_cache", app) +def git(cmd, in_folder=None): + + if in_folder: + cmd = "-C " + in_folder + " " + cmd + cmd = "git " + cmd + return subprocess.check_output(cmd.split(), env=my_env).strip().decode("utf-8") + + def refresh_all_caches(): for app, infos in catalog.items(): @@ -62,13 +74,9 @@ def refresh_cache(app, infos): git("reset origin/master --hard", in_folder=app_cache_folder(app)) -def git(cmd, in_folder=None): - - if in_folder: - cmd = "-C " + in_folder + " " + cmd - cmd = "git " + cmd - return subprocess.check_output(cmd.split()).strip().decode("utf-8") - +################################ +# Actual list build management # +################################ def build_catalog(): @@ -82,7 +90,7 @@ def build_catalog(): try: app_dict = build_app_dict(app, infos) except Exception as e: - error("Adding %s failed: %s" % (app, str(e))) + error("Processing %s failed: %s" % (app, str(e))) continue result_dict[app_dict["id"]] = app_dict @@ -123,24 +131,27 @@ def build_app_dict(app, infos): assert infos["branch"] == "master" + # Make sure we have some cache this_app_cache = app_cache_folder(app) - assert os.path.exists(this_app_cache), "No cache yet for %s" % app - manifest = json.load(open(this_app_cache + "/manifest.json")) - + # If using head, find the most recent meaningful commit in logs if infos["revision"] == "HEAD": relevant_files = ["manifest.json", "actions.json", "hooks/", "scripts/", "conf/", "sources/"] most_recent_relevant_commit = "rev-list --full-history --all -n 1 -- " + " ".join(relevant_files) infos["revision"] = git(most_recent_relevant_commit, in_folder=this_app_cache) assert re.match(r"^[0-9a-f]+$", infos["revision"]), "Output was not a commit? '%s'" % infos["revision"] + # Otherwise, validate commit exists else: assert infos["revision"] in git("rev-list --all", in_folder=this_app_cache).split("\n"), "Revision ain't in history ? %s" % infos["revision"] + # Find timestamp corresponding to that commit timestamp = git("show -s --format=%ct " + infos["revision"], in_folder=this_app_cache) assert re.match(r"^[0-9]+$", timestamp), "Failed to get timestamp for revision ? '%s'" % timestamp timestamp = int(timestamp) + # Build the dict with all the infos + manifest = json.load(open(this_app_cache + "/manifest.json")) return {'id':manifest["id"], 'git': { 'branch': infos['branch'],