Add config.parse_bool()
function
For those generic needs...
This commit is contained in:
parent
9ff8f9ca11
commit
3564178d8d
|
@ -43,6 +43,19 @@ from rattail.logging import TimeConverter
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_bool(value):
|
||||||
|
"""
|
||||||
|
Derive a boolean from the given string value.
|
||||||
|
"""
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
if isinstance(value, bool):
|
||||||
|
return value
|
||||||
|
if value.lower() in ('true', 'yes', 'on', '1'):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def parse_list(value):
|
def parse_list(value):
|
||||||
"""
|
"""
|
||||||
Parse a configuration value, splitting by whitespace and/or commas and
|
Parse a configuration value, splitting by whitespace and/or commas and
|
||||||
|
@ -245,13 +258,7 @@ class RattailConfig(object):
|
||||||
Retrieve a boolean value from config.
|
Retrieve a boolean value from config.
|
||||||
"""
|
"""
|
||||||
value = self.get(*args, **kwargs)
|
value = self.get(*args, **kwargs)
|
||||||
if value is None:
|
return parse_bool(value)
|
||||||
return None
|
|
||||||
if isinstance(value, bool):
|
|
||||||
return value
|
|
||||||
if value.lower() in ('true', 'yes', 'on', '1'):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def getint(self, *args, **kwargs):
|
def getint(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue