updates term output
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
Camera = /media/sdcard
|
Camera = /media/sdcard
|
||||||
|
|
||||||
[jpg]
|
[jpg]
|
||||||
Import = /home/yunohost.app/lychee/import
|
Import = /home/artus/Dev/python/sandbox/import/
|
||||||
Backup = /media/multimedia/artus/Multimedia/Picture/Camera/
|
Backup = /home/artus/Dev/python/sandbox/Picture/
|
||||||
|
|
||||||
[mp4]
|
[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 pathlib import Path
|
||||||
from .store import Store, Backup
|
from .store import Store, Backup
|
||||||
|
from .utils import print_warning
|
||||||
|
|
||||||
class BadConfiguration(Exception):
|
class BadConfiguration(Exception):
|
||||||
pass
|
pass
|
||||||
@@ -13,6 +13,7 @@ class BadConfiguration(Exception):
|
|||||||
def read_config(path):
|
def read_config(path):
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(path)
|
config.read(path)
|
||||||
|
print(config)
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ def parse_config(config):
|
|||||||
import_path = config.get(ext, 'Import')
|
import_path = config.get(ext, 'Import')
|
||||||
imports[ext] = Store(import_path)
|
imports[ext] = Store(import_path)
|
||||||
except configparser.NoOptionError: # Could be wanted by user
|
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:
|
except Exception as err:
|
||||||
raise BadConfiguration(
|
raise BadConfiguration(
|
||||||
f"Could not create import Store at {import_path}:\n{err}")
|
f"Could not create import Store at {import_path}:\n{err}")
|
||||||
@@ -48,4 +49,4 @@ def parse_config(config):
|
|||||||
|
|
||||||
def load_config():
|
def load_config():
|
||||||
# TODO: find first existing file on paths
|
# 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 .store import Content, Store
|
||||||
from .config import load_config, BadConfiguration
|
from .config import load_config, BadConfiguration
|
||||||
|
from .utils import print_error, print_success
|
||||||
|
|
||||||
def find_deleted():
|
def find_deleted():
|
||||||
return Content()
|
return Content()
|
||||||
@@ -12,13 +12,13 @@ def main(opts):
|
|||||||
try:
|
try:
|
||||||
camera_path, backups, imports = load_config()
|
camera_path, backups, imports = load_config()
|
||||||
except BadConfiguration as err:
|
except BadConfiguration as err:
|
||||||
print(f"\x1b[31mError! \x1b[0m\n{err}")
|
print_error(err)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
camera = Store(camera_path)
|
camera = Store(camera_path)
|
||||||
except Exception:
|
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
|
return False
|
||||||
|
|
||||||
if opts.update_card or opts.wipe_card:
|
if opts.update_card or opts.wipe_card:
|
||||||
@@ -27,6 +27,7 @@ def main(opts):
|
|||||||
|
|
||||||
if opts.grab: # Grab new files from camera
|
if opts.grab: # Grab new files from camera
|
||||||
# TODO: gracefully fail if camera is not readable.
|
# TODO: gracefully fail if camera is not readable.
|
||||||
|
print_success("Grabbing...")
|
||||||
camera_files = camera.read_content()
|
camera_files = camera.read_content()
|
||||||
for ext, backup in backups.items():
|
for ext, backup in backups.items():
|
||||||
bkp_files = backup.read_content(exclude_trash=False)
|
bkp_files = backup.read_content(exclude_trash=False)
|
||||||
@@ -37,6 +38,7 @@ def main(opts):
|
|||||||
imports[ext].copy_content(new_files)
|
imports[ext].copy_content(new_files)
|
||||||
|
|
||||||
if opts.sync: # Synchronize deleted files
|
if opts.sync: # Synchronize deleted files
|
||||||
|
print_success("Syncing...")
|
||||||
deleted = find_deleted()
|
deleted = find_deleted()
|
||||||
for ext, backup in backups.items():
|
for ext, backup in backups.items():
|
||||||
backup.trash_content(deleted.filter_by_ext(ext))
|
backup.trash_content(deleted.filter_by_ext(ext))
|
||||||
@@ -47,5 +49,9 @@ def main(opts):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if opts.clean_trash: # Clean the bins
|
if opts.clean_trash: # Clean the bins
|
||||||
|
print_success("Cleaning...")
|
||||||
for _, backup in backups.items():
|
for _, backup in backups.items():
|
||||||
backup.clean_trash()
|
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