first commit
This commit is contained in:
21
__main__.py
Normal file
21
__main__.py
Normal file
@@ -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.
|
||||
|
||||
7
config.py
Normal file
7
config.py
Normal file
@@ -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/"
|
||||
|
||||
|
||||
41
grab.py
Normal file
41
grab.py
Normal file
@@ -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)
|
||||
23
sync.py
Normal file
23
sync.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user