diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-06-14 22:50:55 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-14 22:50:55 +1000 |
| commit | ee7291b7f64a359d17eb1d050086ef5357d79055 (patch) | |
| tree | f1c200d8c8ba81030cbb2113a2be122db6508c8f /src/caelestia/utils/paths.py | |
| parent | Merge pull request #5 from dalpax/patch-1 (diff) | |
| parent | Merge branch 'main' into python-rework (diff) | |
| download | caelestia-cli-ee7291b7f64a359d17eb1d050086ef5357d79055.tar.gz caelestia-cli-ee7291b7f64a359d17eb1d050086ef5357d79055.tar.bz2 caelestia-cli-ee7291b7f64a359d17eb1d050086ef5357d79055.zip | |
Merge pull request #6 from caelestia-dots/python-rework
feat: rewrite in python
Diffstat (limited to 'src/caelestia/utils/paths.py')
| -rw-r--r-- | src/caelestia/utils/paths.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/caelestia/utils/paths.py b/src/caelestia/utils/paths.py new file mode 100644 index 0000000..a4ef36f --- /dev/null +++ b/src/caelestia/utils/paths.py @@ -0,0 +1,53 @@ +import hashlib +import json +import os +import shutil +import tempfile +from pathlib import Path + +config_dir = Path(os.getenv("XDG_CONFIG_HOME", Path.home() / ".config")) +data_dir = Path(os.getenv("XDG_DATA_HOME", Path.home() / ".local/share")) +state_dir = Path(os.getenv("XDG_STATE_HOME", Path.home() / ".local/state")) +cache_dir = Path(os.getenv("XDG_CACHE_HOME", Path.home() / ".cache")) + +c_config_dir = config_dir / "caelestia" +c_data_dir = data_dir / "caelestia" +c_state_dir = state_dir / "caelestia" +c_cache_dir = cache_dir / "caelestia" + +cli_data_dir = Path(__file__).parent.parent / "data" +templates_dir = cli_data_dir / "templates" + +scheme_path = c_state_dir / "scheme.json" +scheme_data_dir = cli_data_dir / "schemes" +scheme_cache_dir = c_cache_dir / "schemes" + +wallpapers_dir = Path.home() / "Pictures/Wallpapers" +wallpaper_path_path = c_state_dir / "wallpaper/path.txt" +wallpaper_link_path = c_state_dir / "wallpaper/current" +wallpaper_thumbnail_path = c_state_dir / "wallpaper/thumbnail.jpg" +wallpapers_cache_dir = c_cache_dir / "wallpapers" + +screenshots_dir = Path.home() / "Pictures/Screenshots" +screenshots_cache_dir = c_cache_dir / "screenshots" + +recordings_dir = Path.home() / "Videos/Recordings" +recording_path = c_state_dir / "record/recording.mp4" +recording_notif_path = c_state_dir / "record/notifid.txt" + + +def compute_hash(path: Path | str) -> str: + sha = hashlib.sha256() + + with open(path, "rb") as f: + while chunk := f.read(8192): + sha.update(chunk) + + return sha.hexdigest() + + +def atomic_dump(path: Path, content: dict[str, any]) -> None: + with tempfile.NamedTemporaryFile("w") as f: + json.dump(content, f) + f.flush() + shutil.move(f.name, path) |