From a774262a3c854345ca98acce5c131ec0eaa1a016 Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Fri, 14 Jun 2019 22:02:59 +0200 Subject: [PATCH] pydoorlock: Config: Only use one config file Signed-off-by: Ralf Ramsauer --- Makefile | 2 +- doorlockd.cfg | 6 ++++++ doorlockd.default.cfg | 11 ----------- pydoorlock/Config.py | 22 ++++++++++++++++++---- 4 files changed, 25 insertions(+), 16 deletions(-) delete mode 100644 doorlockd.default.cfg diff --git a/Makefile b/Makefile index 08f59e1..d59053a 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ install: install doorlockd gpio-wait doorstate $(DESTDIR)/$(PREFIX)/bin/ install doorlockd-passwd $(DESTDIR)/$(PREFIX)/bin/ - install -m 0644 doorlockd.default.cfg doorlockd.cfg $(DESTDIR)/$(SYSCONFDIR) + install -m 0644 doorlockd.cfg $(DESTDIR)/$(SYSCONFDIR) install -m 0644 doorlockd.service doorstate.service $(DESTDIR)/$(SYSCONFDIR)/systemd/system pip install --upgrade --force-reinstall --root=$(DESTDIR) . diff --git a/doorlockd.cfg b/doorlockd.cfg index 9bd21fc..62526a8 100644 --- a/doorlockd.cfg +++ b/doorlockd.cfg @@ -1,5 +1,11 @@ [doorlock] +DEBUG = False +SIMULATE_SERIAL = False +SIMULATE_AUTH = False +RUN_HOOKS = True +SOUNDS = True + # LDAP # LDAP_URI = ldaps://ldap1.binary.kitchen # LDAP_BINDDN = cn=%%s,ou=people,dc=binary-kitchen,dc=de diff --git a/doorlockd.default.cfg b/doorlockd.default.cfg deleted file mode 100644 index d6871f0..0000000 --- a/doorlockd.default.cfg +++ /dev/null @@ -1,11 +0,0 @@ -[DEFAULT] -DEBUG = False -SIMULATE_SERIAL = False -SIMULATE_AUTH = False -RUN_HOOKS = True -SOUNDS = True - -LOCAL_USER_DB = - -LDAP_URI = -LDAP_BINDDN = diff --git a/pydoorlock/Config.py b/pydoorlock/Config.py index ecb129a..c7b6ea9 100644 --- a/pydoorlock/Config.py +++ b/pydoorlock/Config.py @@ -1,7 +1,7 @@ """ Doorlockd -- Binary Kitchen's smart door opener -Copyright (c) Binary Kitchen e.V., 2018 +Copyright (c) Binary Kitchen e.V., 2018-2019 Author: Ralf Ramsauer @@ -16,22 +16,36 @@ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ +import functools from configparser import ConfigParser from os.path import join + +def check_exists(func): + @functools.wraps(func) + def decorator(*args, **kwargs): + config = args[0] + if not config.config.has_option(config.config_topic, args[1]): + return None + return func(*args, **kwargs) + return decorator + + class Config: config_topic = 'doorlock' def __init__(self, sysconfdir): self.config = ConfigParser() - self.config.read([join(sysconfdir, 'doorlockd.default.cfg'), - join(sysconfdir, 'doorlockd.cfg')]) + self.config.read(join(sysconfdir, 'doorlockd.cfg')) + @check_exists def boolean(self, key): return self.config.getboolean(self.config_topic, key) + @check_exists def str(self, key): return self.config.get(self.config_topic, key) + @check_exists def int(self,key): - return self.config.getint(self.config_topic, key) \ No newline at end of file + return self.config.getint(self.config_topic, key)