Merge mqtt backend and plugin #320

Merged
blacklight merged 21 commits from 315/merge-mqtt-backend-and-plugin into master 2023-09-17 02:51:48 +02:00
Showing only changes of commit 3104a59f44 - Show all commits

View file

@ -106,10 +106,11 @@ class Config:
if cfgfile is None: if cfgfile is None:
cfgfile = self._get_default_cfgfile() cfgfile = self._get_default_cfgfile()
cfgfile = os.path.abspath(os.path.expanduser(cfgfile))
if cfgfile is None or not os.path.exists(cfgfile): if cfgfile is None or not os.path.exists(cfgfile):
cfgfile = self._create_default_config() cfgfile = self._create_default_config(cfgfile)
self.config_file = os.path.abspath(os.path.expanduser(cfgfile)) self.config_file = cfgfile
def _init_logging(self): def _init_logging(self):
logging_config = { logging_config = {
@ -211,21 +212,24 @@ class Config:
'variable': {}, 'variable': {},
} }
def _create_default_config(self): @staticmethod
def _create_default_config(cfgfile: Optional[str] = None):
cfg_mod_dir = os.path.dirname(os.path.abspath(__file__)) cfg_mod_dir = os.path.dirname(os.path.abspath(__file__))
# Use /etc/platypush/config.yaml if the user is running as root,
# otherwise ~/.config/platypush/config.yaml if not cfgfile:
cfgfile = ( # Use /etc/platypush/config.yaml if the user is running as root,
( # otherwise ~/.config/platypush/config.yaml
os.path.join(os.environ['XDG_CONFIG_HOME'], 'config.yaml') cfgfile = (
if os.environ.get('XDG_CONFIG_HOME') (
else os.path.join( os.path.join(os.environ['XDG_CONFIG_HOME'], 'config.yaml')
os.path.expanduser('~'), '.config', 'platypush', 'config.yaml' if os.environ.get('XDG_CONFIG_HOME')
else os.path.join(
os.path.expanduser('~'), '.config', 'platypush', 'config.yaml'
)
) )
if not is_root()
else os.path.join(os.sep, 'etc', 'platypush', 'config.yaml')
) )
if not is_root()
else os.path.join(os.sep, 'etc', 'platypush', 'config.yaml')
)
cfgdir = pathlib.Path(cfgfile).parent cfgdir = pathlib.Path(cfgfile).parent
cfgdir.mkdir(parents=True, exist_ok=True) cfgdir.mkdir(parents=True, exist_ok=True)
@ -526,6 +530,7 @@ class Config:
Get a config value or the whole configuration object. Get a config value or the whole configuration object.
:param key: Configuration entry to get (default: all entries). :param key: Configuration entry to get (default: all entries).
:param default: Default value to return if the key is missing.
""" """
# pylint: disable=protected-access # pylint: disable=protected-access
config = cls._get_instance()._config.copy() config = cls._get_instance()._config.copy()