mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-11-16 12:09:10 +01:00
Config.py: Add topic support
Add support to parse keys under different topics Signed-off-by: Thomas Schmid <tom@lfence.de>
This commit is contained in:
parent
18264b0449
commit
b189fe7982
@ -32,8 +32,19 @@ def check_exists(func):
|
|||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def decorator(*args, **kwargs):
|
def decorator(*args, **kwargs):
|
||||||
config = args[0]
|
config = args[0]
|
||||||
if not config.config.has_option(config.config_topic, args[1]):
|
key = args[1]
|
||||||
|
|
||||||
|
if (len(args) == 3):
|
||||||
|
section = args[2]
|
||||||
|
else:
|
||||||
|
section = config.config_topic
|
||||||
|
|
||||||
|
if section is None:
|
||||||
|
section = config.config_topic
|
||||||
|
|
||||||
|
if not config.config.has_option(section, key):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
@ -45,13 +56,22 @@ class Config:
|
|||||||
self.config.read(join(SYSCONFDIR, 'doorlockd.cfg'))
|
self.config.read(join(SYSCONFDIR, 'doorlockd.cfg'))
|
||||||
|
|
||||||
@check_exists
|
@check_exists
|
||||||
def boolean(self, key):
|
def boolean(self, key, topic = None):
|
||||||
return self.config.getboolean(self.config_topic, key)
|
if topic == None:
|
||||||
|
topic = self.config_topic
|
||||||
|
|
||||||
|
return self.config.getboolean(topic, key)
|
||||||
|
|
||||||
@check_exists
|
@check_exists
|
||||||
def str(self, key):
|
def str(self, key, topic = None):
|
||||||
return self.config.get(self.config_topic, key)
|
if topic == None:
|
||||||
|
topic = self.config_topic
|
||||||
|
|
||||||
|
return self.config.get(topic, key)
|
||||||
|
|
||||||
@check_exists
|
@check_exists
|
||||||
def int(self, key):
|
def int(self, key, topic = None):
|
||||||
return self.config.getint(self.config_topic, key)
|
if topic == None:
|
||||||
|
topic = self.config_topic
|
||||||
|
|
||||||
|
return self.config.getint(topic, key)
|
||||||
|
Loading…
Reference in New Issue
Block a user