Skip to content

Commit

Permalink
chg: dev: simplify and remove a dep, use base config instead of file
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen L Arnold <[email protected]>
  • Loading branch information
sarnold committed Aug 11, 2024
1 parent c55eb7c commit 6094a4d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
12 changes: 0 additions & 12 deletions src/timew_status/data/config.yaml

This file was deleted.

35 changes: 21 additions & 14 deletions src/timew_status/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
7 changes: 6 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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}')
Expand Down

0 comments on commit 6094a4d

Please sign in to comment.