forked from endorphant/ttbp
adding file collision checker for backups
parent
3ea6238559
commit
95690d9983
25
ttbp/core.py
25
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_dir = os.path.splitext(os.path.splitext(os.path.basename(filename))[0])[0]
|
||||||
backup_path = os.path.join(config.BACKUPS, backup_dir)
|
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")
|
backup_entries = os.path.join(backup_path, "entries")
|
||||||
|
|
||||||
backups = os.path.listdir(backup_entries)
|
backups = os.listdir(backup_entries)
|
||||||
current = os.path.listdir(config.MAIN_FEELS)
|
current = os.listdir(config.MAIN_FEELS)
|
||||||
|
|
||||||
|
imported = []
|
||||||
|
|
||||||
for feel in backups:
|
for feel in backups:
|
||||||
if os.path.basename(backups) not in current:
|
if os.path.basename(feel) not in current:
|
||||||
print(feel)
|
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
|
||||||
|
|
||||||
|
|
||||||
#############
|
#############
|
||||||
|
|
25
ttbp/ttbp.py
25
ttbp/ttbp.py
|
@ -1014,7 +1014,7 @@ def load_backup():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for filename in os.listdir(config.BACKUPS):
|
for filename in os.listdir(config.BACKUPS):
|
||||||
if "feels-backup" in filename:
|
if "feels-backup" in filename and ".tar" in filename:
|
||||||
backups.append(filename)
|
backups.append(filename)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
subprocess.call(["mkdir", config.BACKUPS])
|
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")
|
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 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:
|
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.")
|
print("congrats! your feels archive has been unloaded.")
|
||||||
else:
|
else:
|
||||||
print("""\
|
print("""\
|
||||||
i've unloaded as much as i can, but there's still some feels i didn't copy over.
|
i've unloaded as much as i can, but there are still some feels i didn't copy
|
||||||
this is probably because you have current feels on the same days, and i didn't
|
over. this is probably because you have current feels on the same days, and i
|
||||||
want to overwrite them.
|
didn't want to overwrite them.
|
||||||
|
|
||||||
you can check out the leftover feels yourself at {directory}!""".format(directory=os.path.join(config.BACKUPS, left)))
|
you can check out the leftover feels yourself at:
|
||||||
|
|
||||||
|
{directory}""".format(directory=tempdir))
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
def show_credits():
|
def show_credits():
|
||||||
|
|
Loading…
Reference in New Issue