Cleanup pane, Pi session tools, review from the UI, project registry, needs panel acts
This commit is contained in:
@@ -114,3 +114,54 @@ def watch_task(cfg):
|
||||
def set_watch(root, cfg, identifier):
|
||||
cfg["watching"] = identifier
|
||||
save(root, cfg)
|
||||
|
||||
|
||||
# --- the registry of adopted projects -------------------------------------
|
||||
#
|
||||
# One project is one folder on one machine. Paperclip owns the project record;
|
||||
# what it cannot know is where the folder is and which session shows it, so that
|
||||
# is kept here, beside the person's other configuration.
|
||||
|
||||
REGISTRY = os.path.join(os.path.expanduser("~"), ".config", "paperclip-harness", "projects.toml")
|
||||
|
||||
|
||||
def register(cfg, name):
|
||||
"""Record an adopted project so it can be listed and switched to later."""
|
||||
os.makedirs(os.path.dirname(REGISTRY), exist_ok=True)
|
||||
rows = {}
|
||||
if os.path.isfile(REGISTRY):
|
||||
with open(REGISTRY, "rb") as f:
|
||||
try:
|
||||
rows = tomllib.load(f).get("projects", {})
|
||||
except Exception:
|
||||
rows = {}
|
||||
key = cfg["paperclip"]["project"]
|
||||
rows[key] = {
|
||||
"name": name,
|
||||
"folder": cfg["machine"]["folder"],
|
||||
"host": cfg["machine"]["host"],
|
||||
"session": cfg["session"],
|
||||
}
|
||||
lines = ["# Adopted projects: one folder, one machine, one session each.",
|
||||
"# Written by bin/office. Paperclip owns the project itself; this is only where it lives.", ""]
|
||||
for k, v in rows.items():
|
||||
lines.append("[projects.%r]" % k)
|
||||
lines.append('name = "%s"' % v["name"])
|
||||
lines.append('folder = "%s"' % v["folder"])
|
||||
lines.append('host = "%s"' % v["host"])
|
||||
lines.append('session = "%s"' % v["session"])
|
||||
lines.append("")
|
||||
with open(REGISTRY, "w") as f:
|
||||
f.write("\n".join(lines))
|
||||
|
||||
|
||||
def registered():
|
||||
"""Every adopted project, as a list of dicts."""
|
||||
if not os.path.isfile(REGISTRY):
|
||||
return []
|
||||
with open(REGISTRY, "rb") as f:
|
||||
try:
|
||||
data = tomllib.load(f)
|
||||
except Exception:
|
||||
return []
|
||||
return [dict(v, id=k) for k, v in data.get("projects", {}).items()]
|
||||
|
||||
Reference in New Issue
Block a user