commit 51294ccec46ff1855eb862b394b0d16c3273ebca Author: artus Date: Thu Nov 15 22:15:58 2018 +0100 first commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..919f59a --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ + +# Photograb + + diff --git a/__main__.py b/__main__.py new file mode 100644 index 0000000..c210efa --- /dev/null +++ b/__main__.py @@ -0,0 +1,21 @@ +#!/bin/python3 +# -*- coding:utf-8 -*- + +""" + Photograb + +""" + +__version__ = "0.1" + +from .grab import grab +from .sync import sync + +# Grab the files +grab() +# Synchronize deleted files, pass --update-card, -u to update the card too. +sync(update_card=False) +# If you want to wipe the card, pass --wipe. +# TODO +# Clean the trash, default behaviour. If you wish to skip it, --no-clean, -n. + diff --git a/config.py b/config.py new file mode 100644 index 0000000..662fd67 --- /dev/null +++ b/config.py @@ -0,0 +1,7 @@ +# -*- coding:utf-8 -*- + +IMPORT_PATH = "/home/yunohost.app/lychee/import/" +BACKUP_PATH = "/media/multimedia/artus/Picture/Camera/original/" +CAMERA_PATH = "/media/sdcard/" + + diff --git a/grab.py b/grab.py new file mode 100644 index 0000000..f06b235 --- /dev/null +++ b/grab.py @@ -0,0 +1,41 @@ +# -*- coding:utf-8 -*- + +""" + Grab photos from camera and store them. +""" +import os +import shutil +import itertools +from .config import CAMERA_PATH, BACKUP_PATH, IMPORT_PATH + + +def _copy_files(files, target_dir): + print("copy {files} to {target_dir}") + # for f in files: + # shutil.copy(f, target_dir) + + +def _get_filenames(folder): + # TODO: exact location of files is lost, but will be used ! + # Could return a dict{ filename: full_path } + return set( + itertools.chain.from_iterable( + filenames for _, _, filenames in os.walk(folder) + )) + + +def backup(files): + _copy_files(files, BACKUP_PATH) + + +def prepare_import(files): + _copy_files(files, IMPORT_PATH) + + +def grab(): + # Get new files from camera + camera_files = _get_filenames(CAMERA_PATH) + backup_files = _get_filenames(BACKUP_PATH) + new_files = camera_files.difference(backup_files) + backup(new_files) + prepare_import(new_files) diff --git a/sync.py b/sync.py new file mode 100644 index 0000000..a974949 --- /dev/null +++ b/sync.py @@ -0,0 +1,23 @@ +# -*- coding:utf-8 -*- + +""" + Synchronize files from gallery. + + Mark deleted files from gallery, to be deleted at later time. +""" +from .trash import move_to_trash + + +def find_deleted(): + pass + + +def delete_from_card(files): + pass + + +def sync(update_card=False): + deleted = find_deleted() + move_to_trash(deleted) + if update_card: + delete_from_card(deleted) diff --git a/trash.py b/trash.py new file mode 100644 index 0000000..5bd7d41 --- /dev/null +++ b/trash.py @@ -0,0 +1,17 @@ +# -*- coding:utf-8 -*- + +""" + Trash container +""" + + +def move_to_trash(files): + pass + + +def manage_trash(): + """ Remove files that have been sitting there for too long """ + pass + + +