From 95690d99838d3ab6c35572e92438804bd9786eed Mon Sep 17 00:00:00 2001 From: Vincent Zeng Date: Wed, 21 Mar 2018 23:34:34 -0400 Subject: [PATCH] adding file collision checker for backups --- ttbp/core.py | 25 +++++++++++++++++++------ ttbp/ttbp.py | 31 ++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/ttbp/core.py b/ttbp/core.py index 6d6c5c2..1a54aea 100644 --- a/ttbp/core.py +++ b/ttbp/core.py @@ -495,18 +495,31 @@ def process_backup(filename): 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]) + if not os.path.exists(backup_path): + 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) + backups = os.listdir(backup_entries) + current = os.listdir(config.MAIN_FEELS) + + imported = [] for feel in backups: - if os.path.basename(backups) not in current: - print(feel) + if os.path.basename(feel) not in current: + imported.append(feel) + return imported + +def import_feels(backups): + """takes a list of filepaths and copies those to current main feels. + + this does not check for collisions. + """ + + pass ############# diff --git a/ttbp/ttbp.py b/ttbp/ttbp.py index b49c081..3bbbeb6 100644 --- a/ttbp/ttbp.py +++ b/ttbp/ttbp.py @@ -1014,7 +1014,7 @@ def load_backup(): try: for filename in os.listdir(config.BACKUPS): - if "feels-backup" in filename: + if "feels-backup" in filename and ".tar" in filename: backups.append(filename) except FileNotFoundError: subprocess.call(["mkdir", config.BACKUPS]) @@ -1027,20 +1027,29 @@ 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 choice is not False: + imports = core.process_backup(os.path.join(config.BACKUPS, backups[choice])) + for feel in imports: + print("importing {feel}".format(feel="-".join(util.parse_date(feel)))) + time.sleep(.01) - if not left: - print("congrats! your feels archive has been unloaded.") + tempdir = os.path.join(config.BACKUPS, os.path.splitext(os.path.splitext(os.path.basename(backups[choice]))[0])[0], "entries") + + if len(imports) == len(os.listdir(tempdir)): + print("congrats! your feels archive has been unloaded.") + else: + print("""\ +i've unloaded as much as i can, but there are 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=tempdir)) 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))) + return input("\n\npress to go back to managing your feels.\n\n") - return def show_credits():