63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
# -*- coding:utf-8 -*-
|
|
|
|
from .store import Content, Store
|
|
from .config import load_config, BadConfiguration
|
|
from .utils import print_error, print_success
|
|
|
|
|
|
def find_imported():
|
|
""" Finds files imported into the gallery """
|
|
return Content()
|
|
|
|
|
|
def main(opts):
|
|
try:
|
|
camera_path, backups, imports = load_config()
|
|
except BadConfiguration as err:
|
|
print_error(err)
|
|
return False
|
|
|
|
try:
|
|
camera = Store(camera_path)
|
|
except Exception:
|
|
print_error(f"Failed to read camera card at {camera_path}")
|
|
return False
|
|
|
|
if opts.update_card or opts.wipe_card:
|
|
# TODO: gracefully fail if camera is not writable.
|
|
pass
|
|
|
|
if opts.grab: # Grab new files from camera
|
|
# TODO: gracefully fail if camera is not readable.
|
|
print_success("Grabbing...")
|
|
camera_files = camera.read_content()
|
|
for ext, backup in backups.items():
|
|
bkp_files = backup.read_content(exclude_trash=False)
|
|
with_ext = camera_files.filter_by_ext(ext)
|
|
new_files = with_ext.difference(bkp_files)
|
|
backup.copy_content(new_files)
|
|
if ext in imports:
|
|
imports[ext].copy_content(new_files)
|
|
|
|
if opts.sync: # Synchronize deleted files
|
|
print_success("Syncing...")
|
|
imported = find_imported()
|
|
for ext, backup in backups.items():
|
|
with_ext = imported.filter_by_ext(ext)
|
|
deleted = backup.difference(with_ext)
|
|
backup.trash_content(deleted)
|
|
if opts.update_card:
|
|
deleted = camera.difference(with_ext)
|
|
camera.remove_content(deleted)
|
|
|
|
if opts.wipe_card: # Wipe the camera memory
|
|
pass
|
|
|
|
if opts.clean_trash: # Clean the bins
|
|
print_success("Cleaning...")
|
|
for _, backup in backups.items():
|
|
backup.clean_trash()
|
|
|
|
print_success("Done !")
|
|
return True
|