summaryrefslogtreecommitdiff
path: root/talerdonations/talerconfig.py
diff options
context:
space:
mode:
Diffstat (limited to 'talerdonations/talerconfig.py')
-rw-r--r--talerdonations/talerconfig.py95
1 files changed, 53 insertions, 42 deletions
diff --git a/talerdonations/talerconfig.py b/talerdonations/talerconfig.py
index 7959ec2..1a33294 100644
--- a/talerdonations/talerconfig.py
+++ b/talerdonations/talerconfig.py
@@ -171,11 +171,13 @@ class Entry:
LOGGER.warning(
"Configuration is missing option '%s' in section '%s',\
falling back to '%s'", self.option,
- self.section, default)
+ self.section, default
+ )
else:
LOGGER.warning(
"Configuration ** is missing option '%s' in section '%s'",
- self.option.upper(), self.section.upper())
+ self.option.upper(), self.section.upper()
+ )
return default
return self.value
@@ -373,7 +375,8 @@ class TalerConfig:
# a error occurs).
def value_string(self, section, option, **kwargs) -> str:
return self.sections[section][option].value_string(
- kwargs.get("default"), kwargs.get("required"), kwargs.get("warn"))
+ kwargs.get("default"), kwargs.get("required"), kwargs.get("warn")
+ )
##
# Get a value from the config that should be a filename.
@@ -388,7 +391,8 @@ class TalerConfig:
# a error occurs).
def value_filename(self, section, option, **kwargs) -> str:
return self.sections[section][option].value_filename(
- kwargs.get("default"), kwargs.get("required"), kwargs.get("warn"))
+ kwargs.get("default"), kwargs.get("required"), kwargs.get("warn")
+ )
##
# Get a integer value from the config.
@@ -402,7 +406,8 @@ class TalerConfig:
# a error occurs).
def value_int(self, section, option, **kwargs) -> int:
return self.sections[section][option].value_int(
- kwargs.get("default"), kwargs.get("required"), kwargs.get("warn"))
+ kwargs.get("default"), kwargs.get("required"), kwargs.get("warn")
+ )
##
# Load default values from canonical locations.
@@ -477,48 +482,58 @@ class TalerConfig:
pair = line.split()
if 2 != len(pair):
LOGGER.error(
- "invalid inlined config filename given ('%s')"
- % line)
+ "invalid inlined config filename given ('%s')" %
+ line
+ )
continue
if pair[1].startswith("/"):
self.load_file(pair[1])
else:
self.load_file(
- os.path.join(os.path.dirname(filename),
- pair[1]))
+ os.path.join(
+ os.path.dirname(filename), pair[1]
+ )
+ )
continue
if line.startswith("["):
if not line.endswith("]"):
LOGGER.error(
- "invalid section header in line %s: %s",
- lineno, repr(line))
+ "invalid section header in line %s: %s", lineno,
+ repr(line)
+ )
section_name = line.strip("[]").strip().strip('"')
current_section = section_name
continue
if current_section is None:
LOGGER.error(
"option outside of section in line %s: %s", lineno,
- repr(line))
+ repr(line)
+ )
continue
pair = line.split("=", 1)
if len(pair) != 2:
- LOGGER.error("invalid option in line %s: %s", lineno,
- repr(line))
+ LOGGER.error(
+ "invalid option in line %s: %s", lineno, repr(line)
+ )
key = pair[0].strip()
value = pair[1].strip()
if value.startswith('"'):
value = value[1:]
if not value.endswith('"'):
- LOGGER.error("mismatched quotes in line %s: %s",
- lineno, repr(line))
+ LOGGER.error(
+ "mismatched quotes in line %s: %s", lineno,
+ repr(line)
+ )
else:
value = value[:-1]
- entry = Entry(self.sections,
- current_section,
- key,
- value=value,
- filename=filename,
- lineno=lineno)
+ entry = Entry(
+ self.sections,
+ current_section,
+ key,
+ value=value,
+ filename=filename,
+ lineno=lineno
+ )
sections[current_section][key] = entry
except FileNotFoundError:
# not logging here, as this interests the final user mostly.
@@ -561,26 +576,22 @@ if __name__ == "__main__":
import argparse
PARSER = argparse.ArgumentParser()
- PARSER.add_argument("--section",
- "-s",
- dest="section",
- default=None,
- metavar="SECTION")
- PARSER.add_argument("--option",
- "-o",
- dest="option",
- default=None,
- metavar="OPTION")
- PARSER.add_argument("--config",
- "-c",
- dest="config",
- default=None,
- metavar="FILE")
- PARSER.add_argument("--filename",
- "-f",
- dest="expand_filename",
- default=False,
- action='store_true')
+ PARSER.add_argument(
+ "--section", "-s", dest="section", default=None, metavar="SECTION"
+ )
+ PARSER.add_argument(
+ "--option", "-o", dest="option", default=None, metavar="OPTION"
+ )
+ PARSER.add_argument(
+ "--config", "-c", dest="config", default=None, metavar="FILE"
+ )
+ PARSER.add_argument(
+ "--filename",
+ "-f",
+ dest="expand_filename",
+ default=False,
+ action='store_true'
+ )
ARGS = PARSER.parse_args()
TC = TalerConfig.from_file(ARGS.config)