diff --git a/lib/logic.py b/lib/logic.py index 4706bd82e1..1179237c05 100644 --- a/lib/logic.py +++ b/lib/logic.py @@ -97,8 +97,8 @@ def __init__(self, smarthome, userlogicconf, envlogicconf): self._userlogicconf = userlogicconf self._env_dir = smarthome._env_dir self._envlogicconf = envlogicconf - self._etc_dir = smarthome._etc_dir - self._logic_dir = smarthome._logic_dir + self._etc_dir = smarthome.get_etcdir() + self._logic_dir = smarthome.get_logicsdir() self._workers = [] self._logics = {} #self._bytecode = {} @@ -897,11 +897,12 @@ def _count_filename_uses(self, conf, filename): Count the number of logics (sections) that reference this filename """ count = 0 - for name in conf: - section = conf.get(name, None) - fn = section.get('filename', None) - if fn is not None and fn.lower() == filename.lower(): - count += 1 + if conf: + for name in conf: + section = conf.get(name, None) + fn = section.get('filename', None) + if fn is not None and fn.lower() == filename.lower(): + count += 1 return count @@ -909,7 +910,6 @@ def filename_used_count(self, filename): # load /etc/logic.yaml conf_filename = os.path.join(self._get_etc_dir(), 'logic') conf = shyaml.yaml_load_roundtrip(conf_filename) - count = self._count_filename_uses(conf, filename) return count diff --git a/lib/smarthome.py b/lib/smarthome.py index 64e9c23cc9..c407c4fb9f 100644 --- a/lib/smarthome.py +++ b/lib/smarthome.py @@ -155,16 +155,12 @@ def initialize_dir_vars(self): self._etc_dir = os.path.join(self._extern_conf_dir, 'etc') - print(f'etc -> {self._etc_dir}') - # 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') @@ -187,7 +183,8 @@ def initialize_dir_vars(self): 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') - self._logic_conf_basename = os.path.join(self._etc_dir, 'logics') + self._logic_conf_basename = os.path.join(self._etc_dir, 'logic') + def create_directories(self): """ @@ -538,6 +535,24 @@ def get_structsdir(self) -> str: return self._structs_dir + def get_logicsdir(self) -> str: + """ + Function to return the logics config directory + + :return: Config directory as an absolute path + """ + return self._logic_dir + + + def get_functionsdir(self) -> str: + """ + Function to return the userfunctions config directory + + :return: Config directory as an absolute path + """ + return self._functions_dir + + def get_vardir(self): """ Function to return the var directory used by SmartHomeNG diff --git a/lib/userfunctions.py b/lib/userfunctions.py index 3bc9883bd9..6f410083e9 100644 --- a/lib/userfunctions.py +++ b/lib/userfunctions.py @@ -91,7 +91,10 @@ def init_lib(shng_base_dir=None, sh=None): else: base_dir = os.getcwd() - _func_dir = os.path.join(base_dir, _uf_subdir) + if _sh: + _func_dir = _sh.get_functionsdir() + else: + _func_dir = os.path.join(base_dir, _uf_subdir) user_modules = [] if os.path.isdir(_func_dir): diff --git a/modules/admin/api_config.py b/modules/admin/api_config.py index 1d00fa5ede..099694a071 100644 --- a/modules/admin/api_config.py +++ b/modules/admin/api_config.py @@ -42,7 +42,7 @@ def __init__(self, module): self.base_dir = self._sh.get_basedir() self.logger = logging.getLogger(__name__.split('.')[0] + '.' + __name__.split('.')[1] + '.' + __name__.split('.')[2][4:]) - self.etc_dir = self._sh._etc_dir + self.etc_dir = self._sh.get_etcdir() self.modules_dir = os.path.join(self.base_dir, 'modules') self.core_conf = shyaml.yaml_load(os.path.join(self.modules_dir, 'core', 'module.yaml')) diff --git a/modules/admin/api_files.py b/modules/admin/api_files.py index b1759238ab..255aa5b4a1 100644 --- a/modules/admin/api_files.py +++ b/modules/admin/api_files.py @@ -51,11 +51,11 @@ def __init__(self, module): self.base_dir = self._sh.get_basedir() self.logger = logging.getLogger(__name__.split('.')[0] + '.' + __name__.split('.')[1] + '.' + __name__.split('.')[2][4:]) - self.etc_dir = self._sh._etc_dir + self.etc_dir = self._sh.get_etcdir() self.items_dir = self._sh._items_dir - self.functions_dir = self._sh._functions_dir + self.functions_dir = self._sh.get_functionsdir() self.scenes_dir = self._sh._scenes_dir - self.logics_dir = self._sh._logic_dir + self.logics_dir = self._sh.get_logicsdir() self.extern_conf_dir = self._sh._extern_conf_dir self.modules_dir = os.path.join(self.base_dir, 'modules') return diff --git a/modules/admin/api_logics.py b/modules/admin/api_logics.py index 78cb5ca835..1db6703428 100644 --- a/modules/admin/api_logics.py +++ b/modules/admin/api_logics.py @@ -49,7 +49,7 @@ def __init__(self, module): self.etc_dir = self._sh._etc_dir - self.logics_dir = os.path.join(self.base_dir, 'logics') + self.logics_dir = self._sh.get_logicsdir() self.logics = Logics.get_instance() self.logger.info("__init__ self.logics = {}".format(self.logics)) self.plugins = Plugins.get_instance()