From 3ea62385599a2a9be68dfedd70b865bdad340a87 Mon Sep 17 00:00:00 2001 From: Vincent Zeng Date: Fri, 16 Mar 2018 22:38:01 -0400 Subject: [PATCH] backup file directory creation --- ttbp/core.py | 23 +++++++++++++++++++++++ ttbp/ttbp.py | 24 ++++++++++++++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/ttbp/core.py b/ttbp/core.py index 00f3645..6d6c5c2 100644 --- a/ttbp/core.py +++ b/ttbp/core.py @@ -486,6 +486,29 @@ def unpublish_feel(filename): if os.path.exists(live_gopher): subprocess.call(["rm", live_gopher]) +def process_backup(filename): + """takes given filename and loads the archive into current main feels. + + ignores any invalidly named files or files that already exist, to avoid + clobbering current feels. ignored files are left in the archive directory + for the user to manually sort out.""" + + backup_dir = os.path.splitext(os.path.splitext(os.path.basename(filename))[0])[0] + backup_path = os.path.join(config.BACKUPS, backup_dir) + subprocess.call(["mkdir", backup_path]) + subprocess.call(["tar", "-C", backup_path, "-xf", filename]) + + backup_entries = os.path.join(backup_path, "entries") + + backups = os.path.listdir(backup_entries) + current = os.path.listdir(config.MAIN_FEELS) + + for feel in backups: + if os.path.basename(backups) not in current: + print(feel) + + + ############# ############# ############# diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index 8a58a24..b49c081 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -612,10 +612,10 @@ def review_menu(intro=""): "read over feels", "modify feels publishing", "backup your feels", + "import a feels backup", "bury some feels", "delete feels by day", "purge all feels", - "import a feels backup", "wipe feels account" ] @@ -647,22 +647,22 @@ def review_menu(intro=""): else: top = nofeels elif choice == 3: - top = DUST + redraw("loading feels backup") + load_backup() elif choice == 4: + top = DUST + elif choice == 5: if hasfeels: redraw("deleting feels") delete_feels() else: top = nofeels - elif choice == 5: + elif choice == 6: if hasfeels: redraw("!!!PURGING ALL FEELS!!!") purge_feels() else: top = nofeels - elif choice == 6: - redraw("loading feels backup") - load_backup() elif choice == 7: redraw("!!! WIPING FEELS ACCOUNT !!!") wipe_account() @@ -1027,6 +1027,18 @@ move it to {directory} and try running this tool again.""".format(directory=conf print("backup files found:\n") choice = menu_handler(backups, "pick a backup file to load (or 'q' to cancel): ", 15, SETTINGS.get("rainbows", False), "backup files found:") + left = core.process_backup(os.path.join(config.BACKUPS, backups[choice])) + + if not left: + print("congrats! your feels archive has been unloaded.") + else: + print("""\ +i've unloaded as much as i can, but there's still some feels i didn't copy over. +this is probably because you have current feels on the same days, and i didn't +want to overwrite them. + +you can check out the leftover feels yourself at {directory}!""".format(directory=os.path.join(config.BACKUPS, left))) + input("\n\npress to go back to managing your feels.\n\n") return