Compare commits
No commits in common. "d69df23f409f624447a7ffdedbf43ecd1b8a3faa" and "96dc04c8fb44df79f776a57a3458e64e12837e32" have entirely different histories.
d69df23f40
...
96dc04c8fb
@ -8,34 +8,12 @@ import shutil
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
from pathlib import Path
|
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:
|
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#*':
|
if ch in '0123456789#*':
|
||||||
return ch + '\uFE0F\u20E3'
|
return ch + '\uFE0F\u20E3'
|
||||||
else:
|
else:
|
||||||
@ -179,7 +157,10 @@ if __name__ == "__main__":
|
|||||||
elif sys.argv[1] == "status":
|
elif sys.argv[1] == "status":
|
||||||
dat = dict()
|
dat = dict()
|
||||||
cache_file = filepath("status")
|
cache_file = filepath("status")
|
||||||
if is_repo_status_outdated(cfg):
|
if is_file_recent(cache_file):
|
||||||
|
with open(cache_file, "rt") as fin:
|
||||||
|
dat = json.load(fin)
|
||||||
|
else:
|
||||||
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 ):
|
||||||
@ -212,11 +193,6 @@ if __name__ == "__main__":
|
|||||||
dat[k] = props
|
dat[k] = props
|
||||||
with open(cache_file, "wt") as fout:
|
with open(cache_file, "wt") as fout:
|
||||||
json.dump(dat, fout, indent = 2)
|
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
|
ml = 0
|
||||||
for k in dat:
|
for k in dat:
|
||||||
ml = len(k) if len(k) > ml else ml
|
ml = len(k) if len(k) > ml else ml
|
||||||
|
Loading…
x
Reference in New Issue
Block a user