updates config and starts testing it
This commit is contained in:
@@ -6,36 +6,38 @@ from pathlib import Path
|
|||||||
from .store import Store, Backup
|
from .store import Store, Backup
|
||||||
|
|
||||||
|
|
||||||
|
class BadConfiguration(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config():
|
||||||
CONFIG = configparser.ConfigParser()
|
CONFIG = configparser.ConfigParser()
|
||||||
wd = Path(__file__).parent
|
wd = Path(__file__).parent
|
||||||
CONFIG.read(wd / "config.ini")
|
CONFIG.read(wd / "config.ini")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
camera = CONFIG.defaults()['camera']
|
camera = CONFIG.defaults()['camera']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise RuntimeError(
|
raise BadConfiguration("No camera path set !")
|
||||||
f"Bad Configuration : No camera path set !")
|
|
||||||
backups = {}
|
backups = {}
|
||||||
imports = {}
|
imports = {}
|
||||||
for ext in CONFIG.sections():
|
for ext in CONFIG.sections():
|
||||||
backup_path = CONFIG.get(ext, 'Backup', fallback=None)
|
|
||||||
import_path = CONFIG.get(ext, 'Import', fallback=None)
|
|
||||||
if backup_path:
|
|
||||||
try:
|
try:
|
||||||
|
backup_path = CONFIG.get(ext, 'Backup')
|
||||||
backups[ext] = Backup(backup_path)
|
backups[ext] = Backup(backup_path)
|
||||||
|
except KeyError: # A section without backup is useless
|
||||||
|
raise BadConfiguration(f"{ext} has no backup path set !")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
raise RuntimeError(
|
raise BadConfiguration(
|
||||||
f"Could not create a Backup at {backup_path}:\n{err}")
|
f"Could not create a Backup at {backup_path}:\n{err}")
|
||||||
else:
|
|
||||||
raise RuntimeError(
|
|
||||||
f"Bad Configuration : {ext} has no backup path set !")
|
|
||||||
if import_path:
|
|
||||||
try:
|
try:
|
||||||
|
import_path = CONFIG.get(ext, 'Import')
|
||||||
imports[ext] = Store(import_path)
|
imports[ext] = Store(import_path)
|
||||||
except Exception as err:
|
except KeyError: # Could be wanted by user
|
||||||
raise RuntimeError(
|
|
||||||
f"Could not create import Store at {import_path}:\n{err}")
|
|
||||||
else:
|
|
||||||
print("Warning : {ext} will not be set to import.")
|
print("Warning : {ext} will not be set to import.")
|
||||||
|
except Exception as err:
|
||||||
|
raise BadConfiguration(
|
||||||
|
f"Could not create import Store at {import_path}:\n{err}")
|
||||||
|
|
||||||
return camera, backups, imports
|
return camera, backups, imports
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
from .store import Content, Store
|
from .store import Content, Store
|
||||||
from .config import load_config
|
from .config import load_config, BadConfiguration
|
||||||
|
|
||||||
|
|
||||||
def find_deleted():
|
def find_deleted():
|
||||||
@@ -11,8 +11,8 @@ def find_deleted():
|
|||||||
def main(opts):
|
def main(opts):
|
||||||
try:
|
try:
|
||||||
camera_path, backups, imports = load_config()
|
camera_path, backups, imports = load_config()
|
||||||
except RuntimeError as err:
|
except BadConfiguration as err:
|
||||||
print(f"\x1b[31m Error ! \x1b[0m\n{err}")
|
print(f"\x1b[31mError! \x1b[0m\n{err}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
# -*- coding:utf-8 -*-
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
|
|
||||||
class TestBackup(unittest.TestCase):
|
|
||||||
|
|
||||||
def test_add(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def test_list(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
21
photograb/test/test_config.py
Normal file
21
photograb/test/test_config.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
class TestLoadConfig(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_default_load_paths(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_raises_exception_on_missing_backup_path(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_warns_on_missing_import_path(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_raises_exception_on_store_init_failure(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_asserts_camera_path_is_present(self):
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user