from pathlib import Path import shutil import appdirs as _appdirs import toml def ensure_directory_exists(path: str): p = Path(path) p.mkdir(parents=True, exist_ok=True) return p 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 = CONFIG_DIR / "config.toml" PACKAGE_ROOT = Path(__file__).absolute().parent if not CONFIG_FILE_PATH.exists(): shutil.copy(PACKAGE_ROOT / "config.toml", CONFIG_FILE_PATH) with CONFIG_FILE_PATH.open("r") as config_file: CONFIG_DATA = toml.load(config_file)