backup file directory creation

This commit is contained in:
Vincent Zeng 2018-03-16 22:38:01 -04:00
부모 e12b72fc72
커밋 3ea6238559
2개의 변경된 파일41개의 추가작업 그리고 6개의 파일을 삭제

파일 보기

@ -486,6 +486,29 @@ def unpublish_feel(filename):
if os.path.exists(live_gopher): if os.path.exists(live_gopher):
subprocess.call(["rm", 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)
############# #############
############# #############
############# #############

파일 보기

@ -612,10 +612,10 @@ def review_menu(intro=""):
"read over feels", "read over feels",
"modify feels publishing", "modify feels publishing",
"backup your feels", "backup your feels",
"import a feels backup",
"bury some feels", "bury some feels",
"delete feels by day", "delete feels by day",
"purge all feels", "purge all feels",
"import a feels backup",
"wipe feels account" "wipe feels account"
] ]
@ -647,22 +647,22 @@ def review_menu(intro=""):
else: else:
top = nofeels top = nofeels
elif choice == 3: elif choice == 3:
top = DUST redraw("loading feels backup")
load_backup()
elif choice == 4: elif choice == 4:
top = DUST
elif choice == 5:
if hasfeels: if hasfeels:
redraw("deleting feels") redraw("deleting feels")
delete_feels() delete_feels()
else: else:
top = nofeels top = nofeels
elif choice == 5: elif choice == 6:
if hasfeels: if hasfeels:
redraw("!!!PURGING ALL FEELS!!!") redraw("!!!PURGING ALL FEELS!!!")
purge_feels() purge_feels()
else: else:
top = nofeels top = nofeels
elif choice == 6:
redraw("loading feels backup")
load_backup()
elif choice == 7: elif choice == 7:
redraw("!!! WIPING FEELS ACCOUNT !!!") redraw("!!! WIPING FEELS ACCOUNT !!!")
wipe_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") 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:") 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") input("\n\npress <enter> to go back to managing your feels.\n\n")
return return