Lazy commit on <function hostname at 0x7f6bcba367a0>.
This commit is contained in:
parent
3092d87f82
commit
753e79d63f
@ -5,6 +5,14 @@ import yaml, sys, subprocess, os
|
||||
import concurrent.futures
|
||||
import re
|
||||
import shutil
|
||||
import json
|
||||
import time
|
||||
|
||||
def is_file_recent(filepath, minutes=10):
|
||||
if not os.path.isfile(filepath):
|
||||
return False
|
||||
mtime = os.path.getmtime(filepath)
|
||||
return (time.time() - mtime) < (minutes * 60)
|
||||
|
||||
def hostname():
|
||||
ret = socket.gethostname().split('.', 1)[0]
|
||||
@ -99,14 +107,24 @@ if __name__ == "__main__":
|
||||
for k in cfg.keys():
|
||||
print(k)
|
||||
elif sys.argv[1] == "status":
|
||||
for k in r:
|
||||
if os.path.exists(cfg[k]["path"]):
|
||||
cmd = "git -C \"{0}\" status --porcelain".format(cfg[k]["path"])
|
||||
output = execute_command(cmd).split("\n")
|
||||
status = "-"
|
||||
if len(output[0]) > 0:
|
||||
status = len(output)
|
||||
print("{0} {1}".format(str(status).rjust(3), k))
|
||||
dat = dict()
|
||||
cache_file = os.path.join(os.environ.get("XDG_CACHE_HOME"), "repo.status")
|
||||
if is_file_recent(cache_file):
|
||||
print("From cache...")
|
||||
with open(cache_file, "rt") as fin:
|
||||
dat = json.load(fin)
|
||||
else:
|
||||
print("Updating cache...")
|
||||
for k in r:
|
||||
if os.path.exists(cfg[k]["path"]):
|
||||
cmd = "git -C \"{0}\" status --porcelain".format(cfg[k]["path"])
|
||||
output = execute_command(cmd).split("\n")
|
||||
dat[k] = 0 if len(output[0]) == 0 else len(output)
|
||||
with open(os.path.join(os.environ.get("XDG_CACHE_HOME"), "repo.status"), "wt") as fout:
|
||||
json.dump(dat, fout, indent = 2)
|
||||
for k in dat:
|
||||
status = "-" if dat[k] == 0 else dat[k]
|
||||
print("{0} {1}".format(str(status).rjust(3), k))
|
||||
elif sys.argv[1] in list( [ "sync", "lc", "lcs", "pull", "push", "fetch" ] ):
|
||||
thread_count = 10
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=thread_count) as executor:
|
||||
|
Loading…
x
Reference in New Issue
Block a user