From a61d0c5a424923d759cf5ead837c68bd38d38c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 26 Jul 2023 14:34:39 +0200 Subject: [PATCH] add dirs module to get toplevel flake and configuration dir --- pkgs/clan-cli/clan_cli/dirs.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 pkgs/clan-cli/clan_cli/dirs.py diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py new file mode 100644 index 0000000..e895df0 --- /dev/null +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -0,0 +1,25 @@ +import os +import sys +from pathlib import Path + + +def get_clan_flake_toplevel() -> Path: + """Returns the path to the toplevel of the clan flake""" + initial_path = Path(os.getcwd()) + path = Path(initial_path) + while path.parent == path: + project_files = [".clan-flake"] + for project_file in project_files: + if (path / project_file).exists(): + return path + path = path.parent + return initial_path + + +def user_data_dir() -> Path: + if sys.platform == "win32": + raise NotImplementedError("Windows is not supported") + 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")))