""" Doorlockd -- Binary Kitchen's smart door opener Copyright (c) Binary Kitchen e.V., 2018-2019 Author: Ralf Ramsauer Thomas Schmid This work is licensed under the terms of the GNU GPL, version 2. See the LICENSE file in the top-level directory. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 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.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)