From 7b2ec936114a99a4c21435d1c8c25ca2e438e5fb Mon Sep 17 00:00:00 2001 From: James Downie Date: Mon, 14 Jul 2025 20:52:22 +1000 Subject: [PATCH 1/3] Lazy commit on . --- jdownie/repo/repo | 114 ++++++++++++++++++++++++++++++---------------- 1 file changed, 76 insertions(+), 38 deletions(-) diff --git a/jdownie/repo/repo b/jdownie/repo/repo index 6732d04..ad471b1 100755 --- a/jdownie/repo/repo +++ b/jdownie/repo/repo @@ -92,10 +92,13 @@ def parse_yaml(file_path): print(f"Error parsing YAML file: {e}") return None -def execute_command(command, dump_error = True): +def execute_command(command, cwd = None, dump_error = True): command = f"/bin/bash -c '{command}'" try: - result = subprocess.run(command, shell=True, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if cwd != None: + result = subprocess.run(command, cwd=cwd, shell=True, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + else: + result = subprocess.run(command, shell=True, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if result.returncode == 0: return result.stdout.strip() else: @@ -108,6 +111,12 @@ def execute_command(command, dump_error = True): print(command) return None +def isFossil(cfg): + ret = False + if "vcs" in cfg.keys(): + ret = ( cfg["vcs"] == "fossil" ) + return ret + def perform_action(action, key, item, silent = False): output = None lbl = "{0}ing".format(action).title() @@ -117,10 +126,17 @@ def perform_action(action, key, item, silent = False): if "push" in item.keys(): push = item["push"] if push or action in list([ "pull", "fetch" ]): - cmd = "git -C \"{0}\" {1}".format(os.path.expanduser(item["path"]), action) - if not silent: - print("{0} {1}...".format(lbl, key)) - output = execute_command(cmd) + if isFossil(item): + cwd = Path(os.path.expanduser(item["path"])) + cmd = f"fossil {action}" + if not silent: + print("{0} {1}...".format(lbl, key)) + output = execute_command(cmd, cwd=cwd) + else: + cmd = "git -C \"{0}\" {1}".format(os.path.expanduser(item["path"]), action) + if not silent: + print("{0} {1}...".format(lbl, key)) + output = execute_command(cmd) rm(filepath("status")) elif action == "sync": if not silent: @@ -137,14 +153,21 @@ def perform_action(action, key, item, silent = False): perform_action("push", key, item, silent=True) rm(filepath("status")) elif action == "lc": - cmd = "git -C \"{0}\" status --porcelain".format(os.path.expanduser(item["path"])) - output = execute_command(cmd).split("\n") - if len(output[0]) > 0: - print("Lazy committing {0}...".format(key)) - cmd = "git -C \"{0}\" add .".format(os.path.expanduser(item["path"])) - output = execute_command(cmd) - cmd = "git -C \"{0}\" commit -m \"Lazy commit on {1}.\"".format(os.path.expanduser(item["path"]), hostname) - output = execute_command(cmd) + if isFossil(item): + cwd = Path(os.path.expanduser(item["path"])) + cmd = f"fossil add ." + output = execute_command(cmd, cwd=cwd) + cmd = f"fossil commit -m \"Lazy commit on {hostname}\"" + output = execute_command(cmd, cwd=cwd) + else: + cmd = "git -C \"{0}\" status --porcelain".format(os.path.expanduser(item["path"])) + output = execute_command(cmd).split("\n") + if len(output[0]) > 0: + print("Lazy committing {0}...".format(key)) + cmd = "git -C \"{0}\" add .".format(os.path.expanduser(item["path"])) + output = execute_command(cmd) + cmd = "git -C \"{0}\" commit -m \"Lazy commit on {1}.\"".format(os.path.expanduser(item["path"]), hostname) + output = execute_command(cmd) rm(filepath("status")) return output @@ -183,31 +206,39 @@ if __name__ == "__main__": for k in r: path = os.path.expanduser( cfg[k]["path"] ) if os.path.exists( path ): - cmd = "git -C \"{0}\" status --porcelain=2 --branch".format( path ) - props = dict() - props["key"] = k - lines = execute_command(cmd).split("\n") n = 0 - for line in lines: - m = re.match(r"# branch\.(\S+)\s+(.+)$", line) - if m: - prop = m.group(1) - rest = m.group(2) - if prop == "ab": - m2 = re.match(r"[+](\d+)\s[-](\d+)", rest) - p2 = rest - if m2: - p2 = dict() - p2["push"] = int(m2.group(1)) - p2["pull"] = int(m2.group(2)) + if isFossil(cfg[k]): + cwd = os.path.expanduser(cfg[k]["path"]) + cmd = "fossil json status" + output = json.loads(execute_command(cmd)) + n = len(output["payload"]["files"]) + cmd = "fossil extras" + n = n + len(execute_command(cmd).split("\n")) + else: + cmd = "git -C \"{0}\" status --porcelain=2 --branch".format( path ) + props = dict() + props["key"] = k + lines = execute_command(cmd).split("\n") + for line in lines: + m = re.match(r"# branch\.(\S+)\s+(.+)$", line) + if m: + prop = m.group(1) + rest = m.group(2) + if prop == "ab": + m2 = re.match(r"[+](\d+)\s[-](\d+)", rest) + p2 = rest + if m2: + p2 = dict() + p2["push"] = int(m2.group(1)) + p2["pull"] = int(m2.group(2)) + props[prop] = p2 props[prop] = p2 - props[prop] = p2 - elif prop == "oid": - props["commit"] = rest + elif prop == "oid": + props["commit"] = rest + else: + props[prop] = rest else: - props[prop] = rest - else: - n = n + 1 + n = n + 1 props["n"] = n dat[k] = props with open(cache_file, "wt") as fout: @@ -245,8 +276,15 @@ if __name__ == "__main__": hosttest = hn in cfg[k]["hosts"] if hosttest and not os.path.exists(os.path.expanduser(cfg[k]["path"])): print("Cloning {0} into {1}...".format(k, os.path.expanduser(cfg[k]["path"]))) - cmd = "git clone \"{0}\" \"{1}\"".format(cfg[k]["url"], os.path.expanduser(cfg[k]["path"])) - output = execute_command(cmd) + if isFossil(cfg[k]): + cwd = Path(os.path.expanduser(cfg[k]["path"])).parent + cmd = "fossil clone --save-http-password \"{0}\"".format(cfg[k]["url"]) + output = execute_command(cmd, cwd=cwd) + with open(os.path.expanduser(f"{cfg[k]['path']}.password"), "wt") as fout: + fout.write(output) + else: + cmd = "git clone \"{0}\" \"{1}\"".format(cfg[k]["url"], os.path.expanduser(cfg[k]["path"])) + output = execute_command(cmd) elif sys.argv[1] == "align": hn = hostname() p = re.compile("^.*Fetch URL: (.*)$") From 5a955556725772e50075f228f243dda8fd1da440 Mon Sep 17 00:00:00 2001 From: James Downie Date: Mon, 14 Jul 2025 21:05:41 +1000 Subject: [PATCH 2/3] Lazy commit on fry. --- jdownie/repo/repo | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jdownie/repo/repo b/jdownie/repo/repo index ad471b1..d96f2e4 100755 --- a/jdownie/repo/repo +++ b/jdownie/repo/repo @@ -119,6 +119,7 @@ def isFossil(cfg): def perform_action(action, key, item, silent = False): output = None + hn = hostname() lbl = "{0}ing".format(action).title() if os.path.exists(os.path.expanduser(item["path"])): if action in list([ "pull", "push", "fetch" ]): @@ -157,7 +158,7 @@ def perform_action(action, key, item, silent = False): cwd = Path(os.path.expanduser(item["path"])) cmd = f"fossil add ." output = execute_command(cmd, cwd=cwd) - cmd = f"fossil commit -m \"Lazy commit on {hostname}\"" + cmd = f"fossil commit -m \"Lazy commit on {hn}\"" output = execute_command(cmd, cwd=cwd) else: cmd = "git -C \"{0}\" status --porcelain".format(os.path.expanduser(item["path"])) @@ -166,7 +167,7 @@ def perform_action(action, key, item, silent = False): print("Lazy committing {0}...".format(key)) cmd = "git -C \"{0}\" add .".format(os.path.expanduser(item["path"])) output = execute_command(cmd) - cmd = "git -C \"{0}\" commit -m \"Lazy commit on {1}.\"".format(os.path.expanduser(item["path"]), hostname) + cmd = "git -C \"{0}\" commit -m \"Lazy commit on {1}.\"".format(os.path.expanduser(item["path"]), hn) output = execute_command(cmd) rm(filepath("status")) return output From b5651612398318fba256413634f423eaf4ac7d72 Mon Sep 17 00:00:00 2001 From: James Downie Date: Mon, 14 Jul 2025 21:13:52 +1000 Subject: [PATCH 3/3] Lazy commit on fry. --- jdownie/repo/repo | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jdownie/repo/repo b/jdownie/repo/repo index d96f2e4..8a30ce0 100755 --- a/jdownie/repo/repo +++ b/jdownie/repo/repo @@ -213,8 +213,13 @@ if __name__ == "__main__": cmd = "fossil json status" output = json.loads(execute_command(cmd)) n = len(output["payload"]["files"]) + print(n) cmd = "fossil extras" - n = n + len(execute_command(cmd).split("\n")) + lines = execute_command(cmd).split("\n") + for line in lines: + if len(line.strip()) > 0: + n = n + 1 + print(n) else: cmd = "git -C \"{0}\" status --porcelain=2 --branch".format( path ) props = dict()