stubbing out archive loading

master
Vincent Zeng 2018-03-16 21:53:52 -04:00
parent c550b51f70
commit e12b72fc72
2 changed files with 45 additions and 6 deletions

View File

@ -74,6 +74,7 @@ TTBPRC = os.path.join(USER_CONFIG, 'ttbprc')
MAIN_FEELS = os.path.join(PATH, 'entries') MAIN_FEELS = os.path.join(PATH, 'entries')
BURIED_FEELS = os.path.join(MAIN_FEELS, 'buried') BURIED_FEELS = os.path.join(MAIN_FEELS, 'buried')
NOPUB = os.path.join(USER_CONFIG, "nopub") NOPUB = os.path.join(USER_CONFIG, "nopub")
BACKUPS = os.path.join(PATH, 'backups')
## UI ## UI

View File

@ -545,7 +545,6 @@ def main_menu():
redraw(intro) redraw(intro)
review_menu(intro) review_menu(intro)
core.load_files() core.load_files()
#core.write_html("index.html")
elif choice == '2': elif choice == '2':
users = core.find_ttbps() users = core.find_ttbps()
prompt = "the following {usercount} {are} recording feels on ttbp:".format( prompt = "the following {usercount} {are} recording feels on ttbp:".format(
@ -662,7 +661,8 @@ def review_menu(intro=""):
else: else:
top = nofeels top = nofeels
elif choice == 6: elif choice == 6:
top = DUST redraw("loading feels backup")
load_backup()
elif choice == 7: elif choice == 7:
redraw("!!! WIPING FEELS ACCOUNT !!!") redraw("!!! WIPING FEELS ACCOUNT !!!")
wipe_account() wipe_account()
@ -789,7 +789,7 @@ def generate_feels_list(user):
def backup_feels(): def backup_feels():
"""creates a tar.gz of user's entries directory""" """creates a tar.gz of user's entries directory"""
backupfile = os.path.join(os.path.expanduser('~'), "feels-backup-"+time.strftime("%Y%m%d%H%M%S")+".tar.gz") backupfile = os.path.join(os.path.expanduser('~'), "feels-backup-"+time.strftime("%Y%m%d-%H%M%S")+".tar.gz")
print("""\ print("""\
i'm preparing all of your entries for backup.""") i'm preparing all of your entries for backup.""")
@ -809,6 +809,10 @@ please enter""")
if ans: if ans:
if not subprocess.call(["tar", "-C", config.PATH, "-czf", backupfile, "entries"]): if not subprocess.call(["tar", "-C", config.PATH, "-czf", backupfile, "entries"]):
subprocess.call(["chmod", "600", backupfile])
if not os.path.exists(config.BACKUPS):
subprocess.call(["mkdir", config.BACKUPS])
subprocess.call(["cp", backupfile, config.BACKUPS])
print("\nbackup saved!") print("\nbackup saved!")
else: else:
print(""" print("""
@ -828,7 +832,7 @@ def delete_feels():
feel = input("""which day's feels do you want to load for deletion? feel = input("""which day's feels do you want to load for deletion?
YYYYMMDD: """) YYYYMMDD (or 'q' to cancel)> """)
if feel in util.BACKS: if feel in util.BACKS:
return return
@ -844,14 +848,15 @@ here's a preview of that feel. press <q> when you're done reviewing!
print("""\ print("""\
sorry, i couldn't find feels for {date}! sorry, i couldn't find feels for {date}!
please try again, or type <q> to cancel.""".format(date=feel)) please try again, or type <q> to cancel.
""".format(date=feel))
return delete_feels() return delete_feels()
print(""" print("""
------------------------------------------------------------- -------------------------------------------------------------
feels deletion is irreversible! if you're sure you want to delete this feel, feels deletion is irreversible! if you're sure you want to delete this feel,
type the date again to confirm, or q to cancel.""") type the date again to confirm, or 'q' to cancel.""")
confirm = input("[{feeldate}]> ".format(feeldate=feel)) confirm = input("[{feeldate}]> ".format(feeldate=feel))
@ -873,6 +878,7 @@ please enter""")
print("okay! please come back any time if you want to delete old feels!") print("okay! please come back any time if you want to delete old feels!")
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")
redraw() redraw()
return return
@ -993,6 +999,38 @@ figure it out!""")
return return
def load_backup():
"""
scans for archive files (prompting for a file location if not found), opens,
copies files to main feels directory (skipping ones that already exist)
"""
print("scanning backup directory at {directory}...".format(directory=config.BACKUPS))
time.sleep(1)
print("...\n")
backups = []
try:
for filename in os.listdir(config.BACKUPS):
if "feels-backup" in filename:
backups.append(filename)
except FileNotFoundError:
subprocess.call(["mkdir", config.BACKUPS])
if len(backups) < 1:
print(""""
sorry, i didn't find any feels backups! if you have a backup file handy, please
move it to {directory} and try running this tool again.""".format(directory=config.BACKUPS))
else:
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:")
input("\n\npress <enter> to go back to managing your feels.\n\n")
return
def show_credits(): def show_credits():
''' '''
prints author acknowledgements and commentary prints author acknowledgements and commentary