updates term output
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
Camera = /media/sdcard
|
||||
|
||||
[jpg]
|
||||
Import = /home/yunohost.app/lychee/import
|
||||
Backup = /media/multimedia/artus/Multimedia/Picture/Camera/
|
||||
Import = /home/artus/Dev/python/sandbox/import/
|
||||
Backup = /home/artus/Dev/python/sandbox/Picture/
|
||||
|
||||
[mp4]
|
||||
Backup = /media/multimedia/artus/Multimedia/Video/Camera/
|
||||
Backup = /home/artus/Dev/python/sandbox/Video/
|
||||
|
||||
@@ -4,7 +4,7 @@ import configparser
|
||||
|
||||
from pathlib import Path
|
||||
from .store import Store, Backup
|
||||
|
||||
from .utils import print_warning
|
||||
|
||||
class BadConfiguration(Exception):
|
||||
pass
|
||||
@@ -13,6 +13,7 @@ class BadConfiguration(Exception):
|
||||
def read_config(path):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(path)
|
||||
print(config)
|
||||
return config
|
||||
|
||||
|
||||
@@ -38,7 +39,7 @@ def parse_config(config):
|
||||
import_path = config.get(ext, 'Import')
|
||||
imports[ext] = Store(import_path)
|
||||
except configparser.NoOptionError: # Could be wanted by user
|
||||
print(f"Warning : {ext} will not be set to import.")
|
||||
print_warning(f"{ext} will not be set to import.")
|
||||
except Exception as err:
|
||||
raise BadConfiguration(
|
||||
f"Could not create import Store at {import_path}:\n{err}")
|
||||
@@ -48,4 +49,4 @@ def parse_config(config):
|
||||
|
||||
def load_config():
|
||||
# TODO: find first existing file on paths
|
||||
parse_config(read_config(Path(__file__).parent / "config.ini"))
|
||||
return parse_config(read_config(Path(__file__).parent / "config.ini"))
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from .store import Content, Store
|
||||
from .config import load_config, BadConfiguration
|
||||
|
||||
from .utils import print_error, print_success
|
||||
|
||||
def find_deleted():
|
||||
return Content()
|
||||
@@ -12,13 +12,13 @@ def main(opts):
|
||||
try:
|
||||
camera_path, backups, imports = load_config()
|
||||
except BadConfiguration as err:
|
||||
print(f"\x1b[31mError! \x1b[0m\n{err}")
|
||||
print_error(err)
|
||||
return False
|
||||
|
||||
try:
|
||||
camera = Store(camera_path)
|
||||
except Exception:
|
||||
print(f"Err: Failed to read camera card at {camera_path}")
|
||||
print_error(f"Failed to read camera card at {camera_path}")
|
||||
return False
|
||||
|
||||
if opts.update_card or opts.wipe_card:
|
||||
@@ -27,6 +27,7 @@ def main(opts):
|
||||
|
||||
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)
|
||||
@@ -37,6 +38,7 @@ def main(opts):
|
||||
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))
|
||||
@@ -47,5 +49,9 @@ def main(opts):
|
||||
pass
|
||||
|
||||
if opts.clean_trash: # Clean the bins
|
||||
print_success("Cleaning...")
|
||||
for _, backup in backups.items():
|
||||
backup.clean_trash()
|
||||
|
||||
print_success("Done !")
|
||||
return True
|
||||
|
||||
16
photograb/utils.py
Normal file
16
photograb/utils.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
|
||||
def print_success(msg):
|
||||
print(f"\x1b[32m{msg}\x1b[0m")
|
||||
|
||||
|
||||
def print_warning(msg):
|
||||
print(f"\x1b[33mWarning :\x1b[0m {msg}")
|
||||
|
||||
|
||||
def print_error(msg):
|
||||
print(f"\x1b[31mError!\x1b[0m")
|
||||
print(msg)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user