diff options
author | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2014-06-09 16:22:23 +0200 |
---|---|---|
committer | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2014-06-09 16:50:14 +0200 |
commit | d7c32d8ce509a16d635569949b1058f832cc0051 (patch) | |
tree | 4e76667b6c27afc13f1ff3874ad85d73ac3a33d8 /pykolab/conf | |
parent | bf56250be719dae16808914e681b8f08980546c3 (diff) | |
download | pykolab-d7c32d8ce509a16d635569949b1058f832cc0051.tar.gz |
Assure when a configuration file is read, it is also configured as the configuration file in use
Diffstat (limited to 'pykolab/conf')
-rw-r--r-- | pykolab/conf/__init__.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/pykolab/conf/__init__.py b/pykolab/conf/__init__.py index 675944a..c5e5b09 100644 --- a/pykolab/conf/__init__.py +++ b/pykolab/conf/__init__.py @@ -377,6 +377,11 @@ class Conf(object): self.cfg_parser = SafeConfigParser() self.cfg_parser.read(value) + if hasattr(self, 'cli_keywords') and hasattr(self.cli_keywords, 'config_file'): + self.cli_keywords.config_file = value + self.defaults.config_file = value + self.config_file = value + def command_get(self, *args, **kw): """ Get a configuration option. @@ -413,10 +418,21 @@ class Conf(object): if not self.cfg_parser.has_section(args[0]): log.error(_("No section '%s' exists.") % (args[0])) - self.cfg_parser.set(args[0], args[1], args[2]) - fp = open(self.cli_keywords.config_file, "w+") - self.cfg_parser.write(fp) - fp.close() + if '%' in args[2]: + value = args[2].replace('%', '%%') + else: + value = args[2] + + self.cfg_parser.set(args[0], args[1], value) + + if hasattr(self, 'cli_keywords') and hasattr(self.cli_keywords, 'config_file'): + fp = open(self.cli_keywords.config_file, "w+") + self.cfg_parser.write(fp) + fp.close() + else: + fp = open(self.config_file, "w+") + self.cfg_parser.write(fp) + fp.close() def create_logger(self): """ |