diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..266c6c5 --- /dev/null +++ b/config.ini @@ -0,0 +1,3 @@ +[maus] +watch_dir = /var/lib/kodi-nfo-feeder/watch +output_dir = /var/lib/kodi-nfo-feeder/output \ No newline at end of file diff --git a/kodi-nfo-feeder.py b/kodi-nfo-feeder.py new file mode 100644 index 0000000..7fd63b5 --- /dev/null +++ b/kodi-nfo-feeder.py @@ -0,0 +1,63 @@ +import os +import logging +from rich.logging import RichHandler +from rich.traceback import install +import configparser + + +class CONST(object): + __slots__ = () + LOG_FORMAT = "%(message)s" + CFG_THIS_FILE_DIRNAME = os.path.dirname(__file__) + CFG_DEFAULT_FILENAME = "config.ini" + CFG_DEFAULT_ABS_PATH = os.path.join(CFG_THIS_FILE_DIRNAME, CFG_DEFAULT_FILENAME) + CFG_KNOWN_DEFAULTS = [ + {"key": "self_name", "value": "kodi-nfo-feeder"}, + {"key": "watch_dir", "value": os.path.join(CFG_THIS_FILE_DIRNAME, "data/var/lib/%(self_name)s/watch")}, + {"key": "output_dir", "value": os.path.join(CFG_THIS_FILE_DIRNAME, "data/var/lib/%(self_name)s/output")} + ] + CFG_KNOWN_SECTION = [ + {"key": "watch_dir", "is_mandatory": True}, + {"key": "output_dir", "is_mandatory": True} + ] + CFG_MANDATORY = [section_cfg["key"] for section_cfg in CFG_KNOWN_SECTION if section_cfg["is_mandatory"]] + + +CONST = CONST() +logging.basicConfig( + # Default for all modules in NOTSET so log everything + level="NOTSET", + format=CONST.LOG_FORMAT, + datefmt="[%X]", + handlers=[RichHandler( + show_time=False if "SYSTEMD_EXEC_PID" in os.environ else True, + rich_tracebacks=True + )] +) +log = logging.getLogger("rich") +# Our own code logs with this level +log.setLevel(logging.DEBUG) +install(show_locals=True) + + +class ConfigParser( + configparser.ConfigParser): + """Can get options() without defaults + + Taken from https://stackoverflow.com/a/12600066. + """ + + def options(self, section, no_defaults=False, **kwargs): + if no_defaults: + try: + return list(self._sections[section].keys()) + except KeyError: + raise configparser.NoSectionError(section) + else: + return super().options(section) + + +ini_defaults = [] +internal_defaults = {default["key"]: default["value"] for default in CONST.CFG_KNOWN_DEFAULTS} +config = ConfigParser(defaults=internal_defaults) +config.read(CONST.CFG_DEFAULT_FILENAME) diff --git a/requirements.in b/requirements.in new file mode 100644 index 0000000..c94be38 --- /dev/null +++ b/requirements.in @@ -0,0 +1 @@ +rich \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a3f3a84 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,12 @@ +# +# This file is autogenerated by pip-compile with python 3.10 +# To update, run: +# +# pip-compile +# +commonmark==0.9.1 + # via rich +pygments==2.11.2 + # via rich +rich==12.0.0 + # via -r requirements.in