backup file directory creation

master
Vincent Zeng 2018-03-16 22:38:01 -04:00
parent e12b72fc72
commit 3ea6238559
2 changed files with 41 additions and 6 deletions

View File

@ -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)
#############
#############
#############

View File

@ -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 <enter> to go back to managing your feels.\n\n")
return