You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
672 B

  1. from pathlib import Path
  2. import shutil
  3. import appdirs as _appdirs
  4. import toml
  5. def ensure_directory_exists(path: str):
  6. p = Path(path)
  7. p.mkdir(parents=True, exist_ok=True)
  8. return p
  9. appdirs = _appdirs.AppDirs("openwrt_backup")
  10. CONFIG_DIR = ensure_directory_exists(appdirs.user_config_dir)
  11. CACHE_DIR = ensure_directory_exists(appdirs.user_cache_dir)
  12. CONFIG_FILE_PATH = CONFIG_DIR / "config.toml"
  13. PACKAGE_ROOT = Path(__file__).absolute().parent
  14. HOSTNAME = 0
  15. NUMBER = 1
  16. if not CONFIG_FILE_PATH.exists():
  17. shutil.copy(PACKAGE_ROOT / "config.toml", CONFIG_FILE_PATH)
  18. with CONFIG_FILE_PATH.open("r") as config_file:
  19. CONFIG_DATA = toml.load(config_file)