Lazy commit on <function hostname at 0x71c961d10180>.
This commit is contained in:
parent
68e4a97d9b
commit
7b2ec93611
@ -92,10 +92,13 @@ def parse_yaml(file_path):
|
|||||||
print(f"Error parsing YAML file: {e}")
|
print(f"Error parsing YAML file: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def execute_command(command, dump_error = True):
|
def execute_command(command, cwd = None, dump_error = True):
|
||||||
command = f"/bin/bash -c '{command}'"
|
command = f"/bin/bash -c '{command}'"
|
||||||
try:
|
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:
|
if result.returncode == 0:
|
||||||
return result.stdout.strip()
|
return result.stdout.strip()
|
||||||
else:
|
else:
|
||||||
@ -108,6 +111,12 @@ def execute_command(command, dump_error = True):
|
|||||||
print(command)
|
print(command)
|
||||||
return None
|
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):
|
def perform_action(action, key, item, silent = False):
|
||||||
output = None
|
output = None
|
||||||
lbl = "{0}ing".format(action).title()
|
lbl = "{0}ing".format(action).title()
|
||||||
@ -117,10 +126,17 @@ def perform_action(action, key, item, silent = False):
|
|||||||
if "push" in item.keys():
|
if "push" in item.keys():
|
||||||
push = item["push"]
|
push = item["push"]
|
||||||
if push or action in list([ "pull", "fetch" ]):
|
if push or action in list([ "pull", "fetch" ]):
|
||||||
cmd = "git -C \"{0}\" {1}".format(os.path.expanduser(item["path"]), action)
|
if isFossil(item):
|
||||||
if not silent:
|
cwd = Path(os.path.expanduser(item["path"]))
|
||||||
print("{0} {1}...".format(lbl, key))
|
cmd = f"fossil {action}"
|
||||||
output = execute_command(cmd)
|
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"))
|
rm(filepath("status"))
|
||||||
elif action == "sync":
|
elif action == "sync":
|
||||||
if not silent:
|
if not silent:
|
||||||
@ -137,14 +153,21 @@ def perform_action(action, key, item, silent = False):
|
|||||||
perform_action("push", key, item, silent=True)
|
perform_action("push", key, item, silent=True)
|
||||||
rm(filepath("status"))
|
rm(filepath("status"))
|
||||||
elif action == "lc":
|
elif action == "lc":
|
||||||
cmd = "git -C \"{0}\" status --porcelain".format(os.path.expanduser(item["path"]))
|
if isFossil(item):
|
||||||
output = execute_command(cmd).split("\n")
|
cwd = Path(os.path.expanduser(item["path"]))
|
||||||
if len(output[0]) > 0:
|
cmd = f"fossil add ."
|
||||||
print("Lazy committing {0}...".format(key))
|
output = execute_command(cmd, cwd=cwd)
|
||||||
cmd = "git -C \"{0}\" add .".format(os.path.expanduser(item["path"]))
|
cmd = f"fossil commit -m \"Lazy commit on {hostname}\""
|
||||||
output = execute_command(cmd)
|
output = execute_command(cmd, cwd=cwd)
|
||||||
cmd = "git -C \"{0}\" commit -m \"Lazy commit on {1}.\"".format(os.path.expanduser(item["path"]), hostname)
|
else:
|
||||||
output = execute_command(cmd)
|
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"))
|
rm(filepath("status"))
|
||||||
return output
|
return output
|
||||||
|
|
||||||
@ -183,31 +206,39 @@ if __name__ == "__main__":
|
|||||||
for k in r:
|
for k in r:
|
||||||
path = os.path.expanduser( cfg[k]["path"] )
|
path = os.path.expanduser( cfg[k]["path"] )
|
||||||
if os.path.exists( 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
|
n = 0
|
||||||
for line in lines:
|
if isFossil(cfg[k]):
|
||||||
m = re.match(r"# branch\.(\S+)\s+(.+)$", line)
|
cwd = os.path.expanduser(cfg[k]["path"])
|
||||||
if m:
|
cmd = "fossil json status"
|
||||||
prop = m.group(1)
|
output = json.loads(execute_command(cmd))
|
||||||
rest = m.group(2)
|
n = len(output["payload"]["files"])
|
||||||
if prop == "ab":
|
cmd = "fossil extras"
|
||||||
m2 = re.match(r"[+](\d+)\s[-](\d+)", rest)
|
n = n + len(execute_command(cmd).split("\n"))
|
||||||
p2 = rest
|
else:
|
||||||
if m2:
|
cmd = "git -C \"{0}\" status --porcelain=2 --branch".format( path )
|
||||||
p2 = dict()
|
props = dict()
|
||||||
p2["push"] = int(m2.group(1))
|
props["key"] = k
|
||||||
p2["pull"] = int(m2.group(2))
|
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
|
||||||
props[prop] = p2
|
elif prop == "oid":
|
||||||
elif prop == "oid":
|
props["commit"] = rest
|
||||||
props["commit"] = rest
|
else:
|
||||||
|
props[prop] = rest
|
||||||
else:
|
else:
|
||||||
props[prop] = rest
|
n = n + 1
|
||||||
else:
|
|
||||||
n = n + 1
|
|
||||||
props["n"] = n
|
props["n"] = n
|
||||||
dat[k] = props
|
dat[k] = props
|
||||||
with open(cache_file, "wt") as fout:
|
with open(cache_file, "wt") as fout:
|
||||||
@ -245,8 +276,15 @@ if __name__ == "__main__":
|
|||||||
hosttest = hn in cfg[k]["hosts"]
|
hosttest = hn in cfg[k]["hosts"]
|
||||||
if hosttest and not os.path.exists(os.path.expanduser(cfg[k]["path"])):
|
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"])))
|
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"]))
|
if isFossil(cfg[k]):
|
||||||
output = execute_command(cmd)
|
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":
|
elif sys.argv[1] == "align":
|
||||||
hn = hostname()
|
hn = hostname()
|
||||||
p = re.compile("^.*Fetch URL: (.*)$")
|
p = re.compile("^.*Fetch URL: (.*)$")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user