Item 8: import warning, bounded update backups, migrated open lessons keep a cycle due. done / next: repeat runs and outputs
This commit is contained in:
1 parent
9632c6addb
commit
7d7f10428a
4 files changed
+83
-2
No files matched your search
+36
-2
@@ -337,7 +337,8 @@ def migrate_learnings():
|
||||
origin = L.normalize_project(old.get("project")) or (prov[0]["project"] if prov else "")
|
||||
if not prov:
|
||||
prov = [{"unit": "legacy:%s" % lid, "project": origin, "ts": old.get("created") or "", "kind": "origin"}]
|
||||
status = {"applied": "implemented", "retired": "reverted"}.get(old.get("status"), "observed")
|
||||
# an old open lesson waits for a cycle, as before: it stays counted by `sisi cycle due`
|
||||
status = {"applied": "implemented", "retired": "reverted", "open": "proposed"}.get(old.get("status"), "observed")
|
||||
kind = old.get("change_kind")
|
||||
target = str(old.get("target") or "")
|
||||
rec = {
|
||||
@@ -483,11 +484,44 @@ def cmd_update(args):
|
||||
return p.returncode
|
||||
|
||||
|
||||
UPDATE_MARK = ".made-by-sisi-update"
|
||||
DEFAULT_KEEP_UPDATE_BACKUPS = 5
|
||||
|
||||
|
||||
def backups_to_keep():
|
||||
"""How many of the update step's own snapshots to keep (config backups.keep_update; at least 1)."""
|
||||
try:
|
||||
n = int((store.config().get("backups") or {}).get("keep_update", DEFAULT_KEEP_UPDATE_BACKUPS))
|
||||
except (TypeError, ValueError):
|
||||
n = DEFAULT_KEEP_UPDATE_BACKUPS
|
||||
return max(n, 1)
|
||||
|
||||
|
||||
def prune_update_backups(current):
|
||||
"""Mark the snapshot just taken as made by the update step, then delete the oldest snapshots
|
||||
carrying that mark beyond the configured number. A folder without the mark is never touched,
|
||||
and the newest one is never deleted. Returns how many were deleted."""
|
||||
base = paths.data_file("backups")
|
||||
try:
|
||||
open(os.path.join(current, UPDATE_MARK), "w").close()
|
||||
mine = sorted(n for n in os.listdir(base) if os.path.isfile(os.path.join(base, n, UPDATE_MARK)))
|
||||
except OSError:
|
||||
return 0
|
||||
doomed = mine[:-backups_to_keep()]
|
||||
for n in doomed:
|
||||
shutil.rmtree(os.path.join(base, n), ignore_errors=True)
|
||||
return len(doomed)
|
||||
|
||||
|
||||
def post_update():
|
||||
"""After the product changed: back up personal data, migrate its format, keep replacements, rebuild, check."""
|
||||
try:
|
||||
pdata.ensure()
|
||||
print("backup: %s" % snapshot("update"))
|
||||
bdir = snapshot("update")
|
||||
print("backup: %s" % bdir)
|
||||
pruned = prune_update_backups(bdir)
|
||||
if pruned:
|
||||
print("removed %d older update backup(s) (keeping %d)" % (pruned, backups_to_keep()))
|
||||
for n in run():
|
||||
print(n)
|
||||
for r in overlay.scan_retests():
|
||||
|
||||
@@ -1789,6 +1789,9 @@ def _cmd_import(args):
|
||||
if not os.path.isfile(args[0]):
|
||||
print("sisi: no such ledger file: %s" % args[0], file=sys.stderr)
|
||||
return 1
|
||||
if not any(r.get("kind") in ("attempt", "run", "amend", "down", "up") for r in read_records(args[0])):
|
||||
print("sisi: warning: %s contains no ledger rows (no line with a kind of attempt, run, amend, "
|
||||
"down or up); is it the right file?" % args[0], file=sys.stderr)
|
||||
before, after, added = import_ledger(args[0])
|
||||
print("imported %d rows from %s (before: %d, after: %d); the original file is unchanged"
|
||||
% (added, args[0], before, after))
|
||||
|
||||
Reference in new issue
Block a user