Skip to content

Commit

Permalink
add snapshot_cleanup.plain_text
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry committed Sep 8, 2021
1 parent f48a56e commit 51a33bf
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion biothings/hub/dataindex/snapshooter.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def cleanup(

if dryrun:
return '\n'.join((
"-" * 75, str(snapshots), "-" * 75,
"-" * 75, cleaner.plain_text(snapshots), "-" * 75,
"DRYRUN ONLY - APPLY THE ACTIONS WITH:",
" > snapshot_cleanup(..., dryrun=False)"
))
Expand Down
49 changes: 48 additions & 1 deletion biothings/hub/dataindex/snapshot_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,53 @@ def _delete(collection, snapshot, envs):
{"$unset": {f"snapshot.{snapshot.attrs['_id']}": 1}}
)

def plain_text(element):
plain_texts = []
assert element.tag == "CleanUps"
for group in element.elems:
assert group.tag == "Group"

plain_texts.append("Snapshots filtered by:")
for k, v in group.attrs.items():
plain_texts.append(f" {k}={repr(v)}")
plain_texts.append("")

removes = group.elems[0].elems
plain_texts.append(f" Found {len(removes)} snapshots to remove:")
for snapshot in removes:
plain_texts.append(" " * 8 + _plain_text(snapshot))

keeps = group.elems[1].elems
plain_texts.append(f" Found {len(keeps)} snapshots to keep:")
for snapshot in keeps:
plain_texts.append(" " * 8 + _plain_text(snapshot))
plain_texts.append("")

return '\n'.join(plain_texts)

def _plain_text(snapshot):
assert snapshot.tag == "Snapshot"
return "".join((
snapshot.attrs["_id"], " (",
f'env={snapshot.attrs.get("environment") or "N/A"}', ", "
f'build_name={repr(snapshot.attrs["build_name"])}', ", ",
f'created_at={str(snapshot.attrs["created_at"])}', ")"
))


# Feature Specification ↑
# https://suwulab.slack.com/archives/CC19LHAF2/p1631126588023700?thread_ts=1631063247.003700&cid=CC19LHAF2

# Snapshots filtered by:
# build_config="demo_allspecies"
# ...

# Found 8 snapshots to remove:
# ...
# Found 3 snapshots to keep:
# ...


def test_find():
from pymongo import MongoClient
logging.basicConfig(level="DEBUG")
Expand All @@ -134,7 +181,7 @@ def test_find():
client = MongoClient("su06")
collection = client["outbreak_hubdb"]["src_build"]

print(find(collection))
print(plain_text(find(collection)))


def test_print():
Expand Down

0 comments on commit 51a33bf

Please sign in to comment.