From 86d792e24daddd6c744800feddbb4ace4d6d5c98 Mon Sep 17 00:00:00 2001 From: Szymon P Date: Thu, 26 Feb 2026 18:25:13 +0100 Subject: [PATCH] make xdg dirs more correct! --- PKGBUILD | 8 ++++---- flake.nix | 9 +++++++++ setup.py | 1 + zut_app/config.py | 19 ------------------- zut_app/zut_client.py | 11 ++++++++--- zut_app/zutui.py | 4 ++-- 6 files changed, 24 insertions(+), 28 deletions(-) delete mode 100644 zut_app/config.py diff --git a/PKGBUILD b/PKGBUILD index d161826..0d07f3c 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,13 +1,13 @@ # Maintainer: _pkgname="zutui" pkgname="$_pkgname-git" -pkgver=1.0.0 -pkgrel=1 +pkgver="1.0.0.r8.ceefa47" +pkgrel=4 pkgdesc="TUI for accessing edziekanat of ZUT university" arch=("any") url="https://github.com/shv187/zutui" license=("MIT") -depends=("python" "python-keyring" "python-textual") +depends=("python" "python-keyring" "python-textual" "python-appdirs" "python-beautifulsoup4" "python-requests") makedepends=("git" "python-build" "python-installer" "python-wheel" "python-setuptools") provides=("zutui") conflicts=("zutui") @@ -16,7 +16,7 @@ sha256sums=("SKIP") pkgver() { cd "$_pkgname" - printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" + printf "1.0.0.r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" } build() { diff --git a/flake.nix b/flake.nix index 9d18d73..10d9e85 100644 --- a/flake.nix +++ b/flake.nix @@ -36,6 +36,7 @@ textual requests beautifulsoup4 + appdirs ]; meta = with pkgs.lib; { @@ -46,6 +47,14 @@ }; }; }; + + devShells = { + default = pkgs.mkShell { + inputsFrom = [ self.packages.${system}.default ]; + }; + }; } + ); + } diff --git a/setup.py b/setup.py index 31ca2f1..1303c0d 100644 --- a/setup.py +++ b/setup.py @@ -10,6 +10,7 @@ setup( "textual", "keyring", "pywin32; sys_platform == 'win32'" + "appdirs", ], entry_points={ 'console_scripts': [ diff --git a/zut_app/config.py b/zut_app/config.py deleted file mode 100644 index da59402..0000000 --- a/zut_app/config.py +++ /dev/null @@ -1,19 +0,0 @@ -import os -import platform - -USER_HOME = os.path.expanduser("~") -WINDOWS_PATH = "zutui" # probably should be in %AppData% or something, but I'm not sure, so I won't change it -LINUX_PATH = ".config/zutui" - -def get_config_path(): - system = platform.system() - if system == "Windows": - APP_DIR = os.path.join(USER_HOME, WINDOWS_PATH) - elif system in ["Linux", "Darwin"]: - APP_DIR = os.path.join(USER_HOME, LINUX_PATH) - else: - print(f"System {system} not supported, aborting...") - exit(1) - if not os.path.exists(APP_DIR): - os.makedirs(APP_DIR) - return APP_DIR diff --git a/zut_app/zut_client.py b/zut_app/zut_client.py index e097633..765b796 100644 --- a/zut_app/zut_client.py +++ b/zut_app/zut_client.py @@ -1,13 +1,18 @@ import requests from bs4 import BeautifulSoup import json +from appdirs import user_config_dir, user_cache_dir import os -from .config import get_config_path +app_name = "zutui" +app_author = "shv187" -APP_DIR = get_config_path() +CONFIG_DIR = user_config_dir(app_name, app_author) +CACHE_DIR = user_cache_dir(app_name, app_author) +os.makedirs(CACHE_DIR, exist_ok=True) +os.makedirs(CONFIG_DIR, exist_ok=True) -CACHE_FILE = os.path.join(APP_DIR, "grades_cache.json") +CACHE_FILE = os.path.join(CACHE_DIR, "grades_cache.json") TIMEOUT = 10 class ZUT: diff --git a/zut_app/zutui.py b/zut_app/zutui.py index 078afa1..bb2b522 100644 --- a/zut_app/zutui.py +++ b/zut_app/zutui.py @@ -3,6 +3,7 @@ import os import keyring from keyring.errors import KeyringError from datetime import datetime +from appdirs import user_config_dir from textual.app import App, ComposeResult from textual.containers import Container from textual.widgets import Header, Footer, DataTable, Label, Button, Input @@ -10,9 +11,8 @@ from textual.screen import Screen from textual.binding import Binding from .zut_client import ZUT -from .config import get_config_path -APP_DIR = get_config_path() +APP_DIR = user_config_dir("zutui", "shv187") CONFIG_FILE = os.path.join(APP_DIR, "config.json") REFRESH_INTERVAL = 1800