summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBotond Hende <nettingman@gmail.com>2024-10-22 21:00:40 +0200
committerBotond Hende <nettingman@gmail.com>2024-10-22 21:00:40 +0200
commit58d23f1f010e5d58b8d9296dae27988c939a53b1 (patch)
treeea12ecb6b11e5831d4182d5cff8a1027e97c33dd
parentb52373f67c830786542b72da96e57b1924a97583 (diff)
default config file and user override
-rw-r--r--__main__.py9
-rw-r--r--config.yaml2
-rw-r--r--modules/config.py27
3 files changed, 34 insertions, 4 deletions
diff --git a/__main__.py b/__main__.py
index bae42ce..8818205 100644
--- a/__main__.py
+++ b/__main__.py
@@ -3,6 +3,7 @@ import sys
import yaml
from pathlib import Path
+from .modules.config import load_config
from .modules.hassil.recognize import recognize
from .modules.hassil.util import merge_dict
from .modules.hassil.intents import Intents, TextSlotList
@@ -11,18 +12,18 @@ from .modules.intents import *
def main():
+ config = load_config()
input_dict = {"intents": {}}
- yaml_path = Path(sys.argv[1])
+ yaml_path = Path(config.intents_dir)
yaml_file_paths = yaml_path.glob("*.yaml")
processes = []
- bin_dir = "/usr/bin"
- for file in os.listdir(bin_dir):
+ for file in os.listdir(config.applications_dir):
if file == "[":
continue
- full_path = os.path.join(bin_dir, file)
+ full_path = os.path.join(config.applications_dir, file)
if os.path.isfile(full_path) or os.path.islink(full_path):
processes.append(file)
diff --git a/config.yaml b/config.yaml
new file mode 100644
index 0000000..bf1b7be
--- /dev/null
+++ b/config.yaml
@@ -0,0 +1,2 @@
+intents_dir: sentences
+applications_dir: /usr/bin \ No newline at end of file
diff --git a/modules/config.py b/modules/config.py
new file mode 100644
index 0000000..602ec8d
--- /dev/null
+++ b/modules/config.py
@@ -0,0 +1,27 @@
+import __main__
+import os.path
+
+import yaml
+
+class Config:
+ def __init__(self):
+ self.intents_dir = ""
+ self.applications_dir = ""
+
+ def update(self, **entries):
+ self.__dict__.update(entries)
+
+ if not self.intents_dir.startswith("/"):
+ self.intents_dir = os.path.join(os.path.dirname(__main__.__file__), self.intents_dir)
+
+def load_config():
+ config = Config()
+ with open(os.path.join(os.path.dirname(__main__.__file__), "config.yaml")) as stream:
+ config.update(**yaml.safe_load(stream))
+
+ user_config = os.path.join(os.environ["HOME"], ".config", "hestia", "config.yaml")
+ if os.path.exists(user_config):
+ with open(user_config) as stream:
+ config.update(**yaml.safe_load(stream))
+
+ return config \ No newline at end of file