diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py index 172d29c78..be8beb59d 100644 --- a/pkgs/clan-cli/clan_cli/dirs.py +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -42,36 +42,15 @@ def user_config_dir() -> Path: return Path(os.getenv("XDG_CONFIG_HOME", os.path.expanduser("~/.config"))) -def user_data_dir() -> Path: - if sys.platform == "win32": - return Path(os.getenv("APPDATA", os.path.expanduser("~\\AppData\\Roaming\\"))) - elif sys.platform == "darwin": - return Path(os.path.expanduser("~/Library/Application Support/")) - else: - return Path(os.getenv("XDG_DATA_HOME", os.path.expanduser("~/.local/share"))) - - -def clan_data_dir() -> Path: - path = user_data_dir() / "clan" - if not path.exists(): - log.debug(f"Creating path with parents {path}") - path.mkdir(parents=True) - return path.resolve() - - def clan_config_dir() -> Path: path = user_config_dir() / "clan" - if not path.exists(): - log.debug(f"Creating path with parents {path}") - path.mkdir(parents=True) + path.mkdir(parents=True, exist_ok=True) return path.resolve() def clan_flakes_dir() -> Path: - path = clan_data_dir() / "flake" - if not path.exists(): - log.debug(f"Creating path with parents {path}") - path.mkdir(parents=True) + path = clan_config_dir() / "flakes" + path.mkdir(parents=True, exist_ok=True) return path.resolve() diff --git a/pkgs/clan-cli/clan_cli/webui/api_inputs.py b/pkgs/clan-cli/clan_cli/webui/api_inputs.py index 105c82273..be3cd0990 100644 --- a/pkgs/clan-cli/clan_cli/webui/api_inputs.py +++ b/pkgs/clan-cli/clan_cli/webui/api_inputs.py @@ -4,21 +4,13 @@ from typing import Any from pydantic import AnyUrl, BaseModel, Extra, validator -from ..dirs import clan_data_dir, clan_flakes_dir +from ..dirs import clan_flakes_dir from ..flakes.create import DEFAULT_URL from ..types import validate_path log = logging.getLogger(__name__) -class ClanDataPath(BaseModel): - directory: Path - - @validator("directory") - def check_directory(cls: Any, v: Path) -> Path: # noqa - return validate_path(clan_data_dir(), v) - - class ClanFlakePath(BaseModel): flake_name: Path diff --git a/pkgs/clan-cli/tests/fixtures_flakes.py b/pkgs/clan-cli/tests/fixtures_flakes.py index cc0ce0738..c50b382b7 100644 --- a/pkgs/clan-cli/tests/fixtures_flakes.py +++ b/pkgs/clan-cli/tests/fixtures_flakes.py @@ -55,7 +55,7 @@ def create_flake( template = Path(__file__).parent / flake_name # copy the template to a new temporary location - flake = temporary_home / ".local/share/clan/flake" / flake_name + flake = temporary_home / ".config/clan/flakes" / flake_name shutil.copytree(template, flake) # lookup the requested machines in ./test_machines and include them diff --git a/pkgs/clan-cli/tests/temporary_dir.py b/pkgs/clan-cli/tests/temporary_dir.py index 026998206..841952d0a 100644 --- a/pkgs/clan-cli/tests/temporary_dir.py +++ b/pkgs/clan-cli/tests/temporary_dir.py @@ -21,7 +21,7 @@ def temporary_home(monkeypatch: pytest.MonkeyPatch) -> Iterator[Path]: else: with tempfile.TemporaryDirectory(prefix="pytest-") as dirpath: monkeypatch.setenv("HOME", str(dirpath)) - monkeypatch.setenv("XDG_DATA_HOME", str(Path(dirpath) / ".local/share")) + monkeypatch.setenv("XDG_CONFIG_HOME", str(Path(dirpath) / ".config")) monkeypatch.chdir(str(dirpath)) log.debug("Temp HOME directory: %s", str(dirpath)) yield Path(dirpath)