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.

24 lines
651 B

  1. import os
  2. import shutil
  3. import appdirs as _appdirs
  4. import toml
  5. def ensure_directory_exists(path):
  6. os.makedirs(path, exist_ok=True)
  7. return path
  8. appdirs = _appdirs.AppDirs("openwrt_backup")
  9. CONFIG_DIR = ensure_directory_exists(appdirs.user_config_dir)
  10. CACHE_DIR = ensure_directory_exists(appdirs.user_cache_dir)
  11. CONFIG_FILE_PATH = os.path.join(CONFIG_DIR, "config.toml")
  12. PACKAGE_ROOT = os.path.dirname(os.path.abspath(__file__))
  13. if not os.path.exists(CONFIG_FILE_PATH):
  14. shutil.copy(os.path.join(PACKAGE_ROOT, "config.toml"), CONFIG_FILE_PATH)
  15. with open(CONFIG_FILE_PATH, "r") as config_file:
  16. CONFIG_DATA = toml.load(config_file)