From 926f42ae6fb1e80bae18473a2bb13f707d650789 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Tue, 26 Jan 2021 01:01:49 -0600 Subject: [PATCH] Started work on the config parser --- config.yml.sample | 9 +++++++++ requirements.txt | 2 ++ setup.py | 1 + tibi_hardlinks/config.py | 23 +++++++++++++++++++++++ tibi_hardlinks/config_parser.py | 0 5 files changed, 35 insertions(+) create mode 100644 config.yml.sample create mode 100644 tibi_hardlinks/config.py delete mode 100644 tibi_hardlinks/config_parser.py diff --git a/config.yml.sample b/config.yml.sample new file mode 100644 index 0000000..e97624d --- /dev/null +++ b/config.yml.sample @@ -0,0 +1,9 @@ +input: + backup_paths: + - "/path/to/backup/location" + - "~/tilde/is/supported" +output: + output_root: "/path/must/be/on/the/same/filesystem" + +customization: + time_format: "%Y-%m-%d_%H-%M-%S" diff --git a/requirements.txt b/requirements.txt index 38dfcb8..81dd2f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ pytz python-dateutil +PyYAML +appdirs diff --git a/setup.py b/setup.py index 8e8869f..174d307 100644 --- a/setup.py +++ b/setup.py @@ -11,4 +11,5 @@ setup( author="Raphael Roberts", author_email="raphael.roberts48@gmail.com", packages=find_packages(), + data_files=[("", ["config.yml.sample"])], ) diff --git a/tibi_hardlinks/config.py b/tibi_hardlinks/config.py new file mode 100644 index 0000000..d43a792 --- /dev/null +++ b/tibi_hardlinks/config.py @@ -0,0 +1,23 @@ +import appdirs as _appdirs +import os +import shutil +import yaml + + +def ensure_directory_exists(path): + os.makedirs(path, exist_ok=True) + return path + + +appdirs = _appdirs.AppDirs("tibi_hardlinks") + +CONFIG_DIR = ensure_directory_exists(appdirs.user_config_dir) +CACHE_DIR = ensure_directory_exists(appdirs.user_cache_dir) +CONFIG_FILE_PATH = os.path.join(CONFIG_DIR, "config.yml") +PACKAGE_ROOT = os.path.dirname(os.path.abspath(__file__)) + +if not os.path.exists(CONFIG_FILE_PATH): + shutil.copy(os.path.join(PACKAGE_ROOT, "config.yml"), CONFIG_FILE_PATH) + +with open(CONFIG_FILE_PATH, "r") as config_file: + CONFIG_DATA = yaml.load(config_file) diff --git a/tibi_hardlinks/config_parser.py b/tibi_hardlinks/config_parser.py deleted file mode 100644 index e69de29..0000000