From 715a705dbea232b5137f56792845c34f70b74849 Mon Sep 17 00:00:00 2001 From: Morg42 <43153739+Morg42@users.noreply.github.com> Date: Sat, 29 Jun 2024 12:22:19 +0200 Subject: [PATCH] lib.smarthome: clean up directory vars --- lib/smarthome.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/smarthome.py b/lib/smarthome.py index 6d1b70ad50..64e9c23cc9 100644 --- a/lib/smarthome.py +++ b/lib/smarthome.py @@ -58,7 +58,7 @@ import logging import logging.handlers import logging.config -import platform # TODO: remove? unused +# import platform # TODO: remove? unused import shutil import signal @@ -66,10 +66,10 @@ import threading import time import traceback -try: - import psutil # TODO: remove? unused -except ImportError: - pass +# try: +# import psutil # TODO: remove? unused +# except ImportError: +# pass BASE = os.path.sep.join(os.path.realpath(__file__).split(os.path.sep)[:-2]) PIDFILE = os.path.join(BASE, 'var', 'run', 'smarthome.pid') @@ -153,37 +153,41 @@ def initialize_dir_vars(self): self._base_dir = BASE self.base_dir = self._base_dir # **base_dir** is deprecated. Use method get_basedir() instead. - for external modules using that var (backend, ...?) - if self._extern_conf_dir != '': - self._etc_dir = os.path.join(self._extern_conf_dir, 'etc') - else: - self._etc_dir = os.path.join(self._base_dir, 'etc') + self._etc_dir = os.path.join(self._extern_conf_dir, 'etc') + + print(f'etc -> {self._etc_dir}') - # decide where to look for config files + # self._conf_dir contains the base dir for config folders if self._config_etc: self._conf_dir = self._etc_dir else: self._conf_dir = self._extern_conf_dir + print(f'conf -> {self._conf_dir}') + + # shng system dirs self._var_dir = os.path.join(self._base_dir, 'var') self._lib_dir = os.path.join(self._base_dir, 'lib') self._plugins_dir = os.path.join(self._base_dir, 'plugins') + # env and var dirs self._env_dir = os.path.join(self._lib_dir, 'env' + os.path.sep) self._env_logic_conf_basename = os.path.join(self._env_dir, 'logic') self._cache_dir = os.path.join(self._var_dir, 'cache' + os.path.sep) + # user config dirs self._items_dir = os.path.join(self._conf_dir, 'items' + os.path.sep) self._structs_dir = os.path.join(self._conf_dir, 'structs') self._logic_dir = os.path.join(self._conf_dir, 'logics' + os.path.sep) + self._functions_dir = os.path.join(self._conf_dir, 'functions' + os.path.sep) + self._scenes_dir = os.path.join(self._conf_dir, 'scenes' + os.path.sep) - self._logic_conf_basename = os.path.join(self._conf_dir, 'logic') - self._log_conf_basename = os.path.join(self._conf_dir, 'logging') - + # system config files + self._smarthome_conf_basename = os.path.join(self._etc_dir, 'smarthome') + self._log_conf_basename = os.path.join(self._etc_dir, 'logging') self._module_conf_basename = os.path.join(self._etc_dir, 'module') self._plugin_conf_basename = os.path.join(self._etc_dir, 'plugin') - - for a in ('conf', 'etc', 'items', 'structs'): - print(f'{a}: {getattr(self, "_" + a + "_dir", "")}') + self._logic_conf_basename = os.path.join(self._etc_dir, 'logics') def create_directories(self): """ @@ -192,8 +196,8 @@ def create_directories(self): os.makedirs(self._structs_dir, mode=0o775, exist_ok=True) os.makedirs(self._var_dir, mode=0o775, exist_ok=True) - os.makedirs(os.path.join(self._var_dir, 'backup'), mode=0o775, exist_ok=True) os.makedirs(self._cache_dir, mode=0o775, exist_ok=True) + os.makedirs(os.path.join(self._var_dir, 'backup'), mode=0o775, exist_ok=True) os.makedirs(os.path.join(self._var_dir, 'db'), mode=0o775, exist_ok=True) os.makedirs(os.path.join(self._var_dir, 'log'), mode=0o775, exist_ok=True) os.makedirs(os.path.join(self._var_dir, 'run'), mode=0o775, exist_ok=True) @@ -220,6 +224,7 @@ def __init__(self, MODE, extern_conf_dir='', config_etc=False): self._mode = MODE self._config_etc = config_etc + self._extern_conf_dir = BASE if extern_conf_dir != '': self._extern_conf_dir = extern_conf_dir