cleans up a little, spots bugs

This commit is contained in:
artus
2018-11-23 21:53:32 +01:00
parent 791d3ea022
commit 5f89969cc5
3 changed files with 8 additions and 7 deletions

View File

@@ -50,4 +50,4 @@ def parse_config(config):
def load_config(): def load_config():
# TODO: find first existing file on paths # TODO: find first existing file on paths
return parse_config(read_config(Path(__file__).parent / "config.ini")) return parse_config(read_config(Path(__file__).parent / "test/config.ini"))

View File

@@ -27,11 +27,10 @@ def main(opts):
# TODO: gracefully fail if camera is not writable. # TODO: gracefully fail if camera is not writable.
pass pass
# Store the content list before grabbing # Store some shared context
camera_files = camera.read_content() camera_files = camera.read_content()
new_files = {} new_files = {}
if opts.grab: # Grab new files from camera if opts.grab: # Grab new files from camera
# TODO: gracefully fail if camera is not readable.
print_success("Grabbing...") print_success("Grabbing...")
for ext, backup in backups.items(): for ext, backup in backups.items():
bkp_files = backup.read_content(exclude_trash=False) bkp_files = backup.read_content(exclude_trash=False)
@@ -51,15 +50,17 @@ def main(opts):
deleted.difference(new_files[ext]) deleted.difference(new_files[ext])
backup.trash_content(deleted) backup.trash_content(deleted)
if opts.update_card: if opts.update_card:
# Use content list before grabbing
# to avoid deleting new files
deleted = camera_files.difference(with_ext) deleted = camera_files.difference(with_ext)
# Do not delete new files while syncing.
# TODO:
# /!\ Unwanted behaviour (remove new files)
# if --grab option is absent
deleted.difference(new_files[ext])
camera.remove_content(deleted) camera.remove_content(deleted)
if opts.wipe_card: # Remove all files from camera if opts.wipe_card: # Remove all files from camera
on_card = camera.read_content()
for ext in backups: for ext in backups:
to_delete = on_card.filter_by_ext(ext) to_delete = camera_files.filter_by_ext(ext)
camera.remove_content(to_delete) camera.remove_content(to_delete)
if opts.clean_trash: # Clean the bins if opts.clean_trash: # Clean the bins