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 concurrent.futures
|
||||||
import re
|
import re
|
||||||
import shutil
|
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():
|
def hostname():
|
||||||
ret = socket.gethostname().split('.', 1)[0]
|
ret = socket.gethostname().split('.', 1)[0]
|
||||||
@ -99,14 +107,24 @@ if __name__ == "__main__":
|
|||||||
for k in cfg.keys():
|
for k in cfg.keys():
|
||||||
print(k)
|
print(k)
|
||||||
elif sys.argv[1] == "status":
|
elif sys.argv[1] == "status":
|
||||||
for k in r:
|
dat = dict()
|
||||||
if os.path.exists(cfg[k]["path"]):
|
cache_file = os.path.join(os.environ.get("XDG_CACHE_HOME"), "repo.status")
|
||||||
cmd = "git -C \"{0}\" status --porcelain".format(cfg[k]["path"])
|
if is_file_recent(cache_file):
|
||||||
output = execute_command(cmd).split("\n")
|
print("From cache...")
|
||||||
status = "-"
|
with open(cache_file, "rt") as fin:
|
||||||
if len(output[0]) > 0:
|
dat = json.load(fin)
|
||||||
status = len(output)
|
else:
|
||||||
print("{0} {1}".format(str(status).rjust(3), k))
|
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" ] ):
|
elif sys.argv[1] in list( [ "sync", "lc", "lcs", "pull", "push", "fetch" ] ):
|
||||||
thread_count = 10
|
thread_count = 10
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=thread_count) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=thread_count) as executor:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user