Skip to content

Commit

Permalink
lib.smarthome: clean up directory vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Morg42 committed Jun 29, 2024
1 parent 3c074a2 commit 715a705
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions lib/smarthome.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@
import logging
import logging.handlers
import logging.config
import platform # TODO: remove? unused
# import platform # TODO: remove? unused
import shutil

import signal
import subprocess
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')
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 715a705

Please sign in to comment.