From da99efeb63de3dff5879b2c06f946c00328bd39c Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Tue, 25 May 2021 23:28:45 -0500 Subject: [PATCH] Fixed missing quotes for config paths and copied config.py from another project --- config.toml.template | 6 +++--- openwrt_backup/config.py | 24 ++++++++++++++++++++++++ requirements.txt | 1 + 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/config.toml.template b/config.toml.template index 2e25b69..9e4a8d0 100644 --- a/config.toml.template +++ b/config.toml.template @@ -1,10 +1,10 @@ [ssh] -root = ~/.ssh +root = "~/.ssh" [router] -temp = /tmp +temp = "/tmp" [backup] -path = ~/Documents/router-backup +path = "~/Documents/router-backup" time_format="%Y-%m-%d_%H-%M-%S" keep = 5 diff --git a/openwrt_backup/config.py b/openwrt_backup/config.py index e69de29..5ca91bb 100644 --- a/openwrt_backup/config.py +++ b/openwrt_backup/config.py @@ -0,0 +1,24 @@ +import os +import shutil + +import appdirs as _appdirs +import toml + + +def ensure_directory_exists(path): + os.makedirs(path, exist_ok=True) + return path + + +appdirs = _appdirs.AppDirs("openwrt_backup") + +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.toml") +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.toml"), CONFIG_FILE_PATH) + +with open(CONFIG_FILE_PATH, "r") as config_file: + CONFIG_DATA = toml.load(config_file) diff --git a/requirements.txt b/requirements.txt index 913b210..80ba784 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ paramiko toml +appdirs