baby crying... was adding Path objects
This commit is contained in:
@@ -4,17 +4,65 @@
|
||||
"""
|
||||
Photograb
|
||||
|
||||
USAGE:
|
||||
|
||||
--grab, -g : Grab files from camera.
|
||||
--sync, -s : Sync deleted files from gallery.
|
||||
--update-card, -u : Use with --sync, also delete trashed files from camera.
|
||||
--wipe-card : Completely wipe the camera.
|
||||
--clean-trash, -t : Clean the trash
|
||||
--all, -a : Perform all tasks, equivalent to -gst.
|
||||
|
||||
EXAMPLES :
|
||||
|
||||
Run all tasks, including update card :
|
||||
$ photograb -au
|
||||
|
||||
Only clean trash :
|
||||
$ photograb --clean-trash
|
||||
|
||||
"""
|
||||
|
||||
__version__ = "0.1"
|
||||
|
||||
import argparse
|
||||
from .grab import grab
|
||||
from .sync import sync
|
||||
from .trash import manage_trash
|
||||
|
||||
# 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.
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-a', '--all', action="store_true")
|
||||
parser.add_argument('-g', '--grab', action="store_true")
|
||||
parser.add_argument('-s', '--sync', action="store_true")
|
||||
parser.add_argument('-t', '--clean-trash', action="store_true")
|
||||
parser.add_argument('-u', '--update-card', action="store_true")
|
||||
parser.add_argument('--wipe-card', action="store_true")
|
||||
opts = parser.parse_args()
|
||||
|
||||
|
||||
# --all, -a : Perform all actions (except --wipe-card !)
|
||||
if opts.all:
|
||||
opts.grab = True
|
||||
opts.sync = True
|
||||
opts.clean_trash = True
|
||||
|
||||
# Do not update card if we are going to wipe it anyway.
|
||||
if opts.wipe_card:
|
||||
opts.update_card = False
|
||||
|
||||
print(opts)
|
||||
|
||||
# --grab, -g : Grab the files
|
||||
if opts.grab:
|
||||
grab()
|
||||
# --sync, -c : Synchronize deleted files
|
||||
# --update-card, -u : Update the card too.
|
||||
if opts.sync:
|
||||
sync(update_card=opts.update_card)
|
||||
# --wipe : Completely wipe the card.
|
||||
if opts.wipe_card:
|
||||
# TODO
|
||||
pass
|
||||
# --clean-trash, -t : Clean the trash.
|
||||
if opts.clean_trash:
|
||||
manage_trash()
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
IMPORT_PATH = "/home/yunohost.app/lychee/import/"
|
||||
BACKUP_PATH = "/media/multimedia/artus/Picture/Camera/original/"
|
||||
CAMERA_PATH = "/media/sdcard/"
|
||||
from pathlib import Path
|
||||
|
||||
IMPORT_PATH = Path("/home/yunohost.app/lychee/import/")
|
||||
BACKUP_PATH = Path("/media/multimedia/artus/Picture/Camera/original/")
|
||||
CAMERA_PATH = Path("/media/sdcard/")
|
||||
|
||||
TRASH_NAME = ".trash"
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"""
|
||||
Grab photos from camera and store them.
|
||||
"""
|
||||
from .utils import copy_files, get_filenames
|
||||
from .utils import copy_files, get_content
|
||||
from .config import CAMERA_PATH, IMPORT_PATH
|
||||
from . import backup
|
||||
|
||||
@@ -14,7 +14,7 @@ def prepare_import(content):
|
||||
|
||||
def grab():
|
||||
# Get new files from camera
|
||||
camera_files = get_filenames(CAMERA_PATH)
|
||||
camera_files = get_content(CAMERA_PATH)
|
||||
backup_files = backup.list(exclude_trash=False)
|
||||
new_files = camera_files.difference(backup_files)
|
||||
backup.add(new_files)
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
import shutil
|
||||
import time
|
||||
from . import trash
|
||||
from .utils import get_content
|
||||
from .utils import get_content, Content
|
||||
from .config import CAMERA_PATH
|
||||
|
||||
|
||||
def find_deleted():
|
||||
pass
|
||||
return Content()
|
||||
|
||||
|
||||
def remove_trashed_from_card():
|
||||
@@ -27,7 +27,7 @@ def remove_trashed_from_card():
|
||||
shutil.rm(path)
|
||||
del_count += 1
|
||||
elapsed = time.process_time() - start_time
|
||||
print(f"{del_count} in {elapsed}s.")
|
||||
print(f"{del_count} in {elapsed:.2f}s.")
|
||||
|
||||
|
||||
def sync(update_card=False):
|
||||
|
||||
@@ -3,13 +3,17 @@
|
||||
"""
|
||||
Trash container
|
||||
"""
|
||||
|
||||
import os
|
||||
from .utils import move_files, get_content
|
||||
from .config import BACKUP_PATH, TRASH_NAME
|
||||
|
||||
TRASH_PATH = BACKUP_PATH + "/" + TRASH_NAME
|
||||
TRASH_PATH = BACKUP_PATH + TRASH_NAME
|
||||
|
||||
|
||||
def add(files):
|
||||
# Ensure trash folder exists
|
||||
if not os.exists(TRASH_PATH):
|
||||
os.mkdir(TRASH_PATH)
|
||||
move_files(files, TRASH_PATH)
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
import itertools
|
||||
import os
|
||||
import time
|
||||
# import shutil
|
||||
|
||||
|
||||
def copy_files(content, target_dir):
|
||||
print(f"copy {content} to {target_dir}")
|
||||
print(f"Copy files to {target_dir} : ", end="")
|
||||
count = len(content)
|
||||
start_time = time.process_time()
|
||||
# for name,path in content.items():
|
||||
# shutil.copy(path, target_dir)
|
||||
elapsed = time.process_time() - start_time
|
||||
print(f"{count} in {elapsed:.2f}s.")
|
||||
|
||||
|
||||
def move_files(content, target_dir):
|
||||
print(f"move {content} to {target_dir}")
|
||||
print(f"Move files to {target_dir} : ", end="")
|
||||
count = len(content)
|
||||
start_time = time.process_time()
|
||||
# for name, path in content.items():
|
||||
# shutil.mv(path, target_dir)
|
||||
elapsed = time.process_time() - start_time
|
||||
print(f"{count} in {elapsed:.2f}s.")
|
||||
|
||||
|
||||
class Content(dict):
|
||||
|
||||
Reference in New Issue
Block a user