Files
photograb/photograb/main.py
2018-11-23 20:58:32 +01:00

58 lines
1.7 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_deleted():
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...")
deleted = find_deleted()
for ext, backup in backups.items():
backup.trash_content(deleted.filter_by_ext(ext))
if opts.update_card:
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