From 6094a4db8b08a7b976b14887a5260a7c544795fa Mon Sep 17 00:00:00 2001 From: Stephen L Arnold Date: Sun, 11 Aug 2024 16:33:08 -0700 Subject: [PATCH] chg: dev: simplify and remove a dep, use base config instead of file Signed-off-by: Stephen L Arnold --- setup.cfg | 2 -- src/timew_status/data/config.yaml | 12 ----------- src/timew_status/utils.py | 35 ++++++++++++++++++------------- tests/test_utils.py | 7 ++++++- 4 files changed, 27 insertions(+), 29 deletions(-) delete mode 100644 src/timew_status/data/config.yaml diff --git a/setup.cfg b/setup.cfg index 9651bb2..95e4f25 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,12 +33,10 @@ setup_requires = install_requires = importlib-metadata; python_version < '3.8' - importlib-resources; python_version < '3.10' munch[yaml] timew-report pycairo PyGObject - pyxdg packages = find_namespace: package_dir = diff --git a/src/timew_status/data/config.yaml b/src/timew_status/data/config.yaml deleted file mode 100644 index f9e8fab..0000000 --- a/src/timew_status/data/config.yaml +++ /dev/null @@ -1,12 +0,0 @@ -# time strings are HH:MM (no seconds) -day_max: "08:00" -day_snooze: "01:00" -seat_max: "01:30" -seat_snooze: "00:40" -seat_reset_on_stop: false -use_last_tag: false -default_jtag_str: vct-sw,implement skeleton timew indicator -jtag_separator: "," -loop_idle_seconds: 20 -show_state_label: false -terminal_emulator: gnome-terminal diff --git a/src/timew_status/utils.py b/src/timew_status/utils.py index a91a63f..f398dd2 100644 --- a/src/timew_status/utils.py +++ b/src/timew_status/utils.py @@ -2,20 +2,28 @@ """ import os import subprocess -import sys from datetime import timedelta from pathlib import Path from munch import Munch -from xdg import BaseDirectory - -if sys.version_info < (3, 10): - import importlib_resources -else: - import importlib.resources as importlib_resources APP_NAME = 'timew_status_indicator' -APP_AUTHOR = "nerdboy" +CFG = Munch.fromYAML( + """ + # time strings are HH:MM (no seconds) + day_max: "08:00" + day_snooze: "01:00" + seat_max: "01:30" + seat_snooze: "00:40" + seat_reset_on_stop: false + use_last_tag: false + default_jtag_str: vct-sw,implement skeleton timew indicator + jtag_separator: "," + loop_idle_seconds: 20 + show_state_label: false + terminal_emulator: gnome-terminal + """ +) def get_config(file_encoding='utf-8'): @@ -32,9 +40,7 @@ def get_config(file_encoding='utf-8'): cfgdir = get_userdirs() cfgfile = cfgdir.joinpath('config.yaml') if not cfgfile.exists(): - default = importlib_resources.files('timew_status.data').joinpath('config.yaml') - defcfg = Munch.fromYAML(default.read_text(encoding=file_encoding)) - cfgfile.write_text(Munch.toYAML(defcfg), encoding=file_encoding) + cfgfile.write_text(Munch.toYAML(CFG), encoding=file_encoding) cfgobj = Munch.fromYAML(cfgfile.read_text(encoding=file_encoding)) return cfgobj, cfgfile @@ -138,9 +144,11 @@ def get_userdirs(): :return configdir: Path obj """ - configdir = BaseDirectory.save_config_path(APP_NAME) + config_home = os.getenv('XDG_CONFIG_HOME') or Path.home().joinpath('.config') + configdir = config_home.joinpath(APP_NAME) + configdir.mkdir(parents=True, exist_ok=True) - return Path(configdir) + return configdir def parse_for_tag(text): @@ -202,5 +210,4 @@ def to_td(h): return timedelta(hours=int(hrs), minutes=int(mins), seconds=int(secs)) -CFG, _ = Munch.toDict(get_config()) DEBUG = os.getenv('DEBUG', default=None) diff --git a/tests/test_utils.py b/tests/test_utils.py index f6d01cd..038dc4c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,4 @@ -from timew_status.utils import get_config, parse_for_tag +from timew_status.utils import get_config, get_userdirs, parse_for_tag start_txt = """ Note: '"vct-sw,refactor timew indicator config to yaml"' is a new tag. @@ -24,6 +24,11 @@ def test_get_config(): print(cfgobj) +def test_get_userdirs(): + udir = get_userdirs() + print(f'\nuserdir: {udir}') + + def test_parse_for_tag(): ret = parse_for_tag(start_txt) print(f'\n{ret}')