Compare commits
2 Commits
96dc04c8fb
...
d69df23f40
Author | SHA1 | Date | |
---|---|---|---|
d69df23f40 | |||
cdfe8f05b5 |
@ -8,12 +8,34 @@ import shutil
|
||||
import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
def get_latest_git_mtime(repos: dict) -> float:
|
||||
max_mtime = 0.0
|
||||
for k, info in repos.items():
|
||||
repo_path = os.path.expanduser(info.get("path"))
|
||||
if not repo_path:
|
||||
continue
|
||||
git_dir = os.path.join(repo_path, ".git")
|
||||
try:
|
||||
mtime = os.path.getmtime(git_dir)
|
||||
max_mtime = max(max_mtime, mtime)
|
||||
except (FileNotFoundError, NotADirectoryError):
|
||||
continue
|
||||
return max_mtime
|
||||
|
||||
def is_repo_status_outdated(repos):
|
||||
latest_mtime = get_latest_git_mtime(repos)
|
||||
last_mtime = 0
|
||||
if os.path.exists(filepath("mtime")):
|
||||
with open(filepath("mtime"), "rt") as fin:
|
||||
content = fin.read().strip()
|
||||
print(f"content: {content}")
|
||||
last_mtime = float(content)
|
||||
print(f"{latest_mtime} {last_mtime}")
|
||||
return latest_mtime > last_mtime
|
||||
|
||||
def to_keycap(ch: str) -> str:
|
||||
"""
|
||||
Converts a single character (0-9, #, *) into a keycap emoji.
|
||||
Returns the original character if not valid for keycaps.
|
||||
"""
|
||||
if ch in '0123456789#*':
|
||||
return ch + '\uFE0F\u20E3'
|
||||
else:
|
||||
@ -157,10 +179,7 @@ if __name__ == "__main__":
|
||||
elif sys.argv[1] == "status":
|
||||
dat = dict()
|
||||
cache_file = filepath("status")
|
||||
if is_file_recent(cache_file):
|
||||
with open(cache_file, "rt") as fin:
|
||||
dat = json.load(fin)
|
||||
else:
|
||||
if is_repo_status_outdated(cfg):
|
||||
for k in r:
|
||||
path = os.path.expanduser( cfg[k]["path"] )
|
||||
if os.path.exists( path ):
|
||||
@ -193,6 +212,11 @@ if __name__ == "__main__":
|
||||
dat[k] = props
|
||||
with open(cache_file, "wt") as fout:
|
||||
json.dump(dat, fout, indent = 2)
|
||||
with open(filepath("mtime"), "wt") as fout:
|
||||
fout.write(str(get_latest_git_mtime(cfg)))
|
||||
else:
|
||||
with open(cache_file, "rt") as fin:
|
||||
dat = json.load(fin)
|
||||
ml = 0
|
||||
for k in dat:
|
||||
ml = len(k) if len(k) > ml else ml
|
||||
|
Loading…
x
Reference in New Issue
Block a user