aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/config')
-rw-r--r--src/mailman_pgp/config/config.py31
-rw-r--r--src/mailman_pgp/config/converter.py13
2 files changed, 27 insertions, 17 deletions
diff --git a/src/mailman_pgp/config/config.py b/src/mailman_pgp/config/config.py
index 7999e65..0b5fe4f 100644
--- a/src/mailman_pgp/config/config.py
+++ b/src/mailman_pgp/config/config.py
@@ -31,6 +31,15 @@ from mailman_pgp.config.validator import ConfigValidator
class Config(ConfigParser):
"""A ConfigParser with a name."""
+ def __init__(self):
+ super().__init__()
+ self.name = None
+ self.dict = None
+ schema = resource_string('mailman_pgp.config',
+ 'schema.cfg').decode('utf-8')
+ self.validator = ConfigValidator(schema)
+ self.converter = ConfigConverter(schema)
+
def load(self, name):
"""
Load the plugin configuration, and set our name.
@@ -43,19 +52,15 @@ class Config(ConfigParser):
dict(mailman_config.plugin_configs)[self.name].configuration))
def validate(self):
- """
-
- """
- validator = ConfigValidator(
- resource_string('mailman_pgp.config',
- 'schema.cfg').decode('utf-8'))
- validator.validate(self)
+ self.validator.validate(self)
def convert(self):
- """
+ self.dict = self.converter.convert(self)
- """
- converter = ConfigConverter(
- resource_string('mailman_pgp.config',
- 'schema.cfg').decode('utf-8'))
- converter.convert(self)
+ def get_value(self, section, option):
+ return self.dict[section][option]
+
+ def set(self, section, option, value=None):
+ self.dict[section][option] = self.converter.converter(section, option)(
+ value)
+ return super().set(section, option, value)
diff --git a/src/mailman_pgp/config/converter.py b/src/mailman_pgp/config/converter.py
index ac2cf22..e3cdb90 100644
--- a/src/mailman_pgp/config/converter.py
+++ b/src/mailman_pgp/config/converter.py
@@ -40,12 +40,13 @@ class ConfigConverter:
for section in self.schema.sections():
out[section] = dict()
for option in self.schema.options(section):
- out[section][option] = self._transform_option(
- cfg.get(section, option),
- self.schema.get(section, option))
+ out[section][option] = self._transform_option(section, option,
+ cfg.get(section,
+ option))
return out
- def _transform_option(self, value, schema):
+ def converter(self, section, option):
+ schema = self.schema.get(section, option)
call = None
try:
call = getattr(builtins, schema)
@@ -59,6 +60,10 @@ class ConfigConverter:
if match is None:
raise ValueError
return match.group()
+ return call
+
+ def _transform_option(self, section, option, value):
+ call = self.converter(section, option)
if call is None:
raise ValueError