From: Markus Lehtonen Date: Wed, 22 Aug 2012 10:07:34 +0000 (+0300) Subject: Fix replacing of keys in config manager X-Git-Tag: 0.10~59^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4a98291b84fd2328ad273e454058c757e9738553;p=tools%2Fgbs.git Fix replacing of keys in config manager Otherwise cmd_build will crash if 'passwd' are being replaced with 'passwdx'. Signed-off-by: Markus Lehtonen --- diff --git a/gitbuildsys/conf.py b/gitbuildsys/conf.py index 02744e2..95fced7 100644 --- a/gitbuildsys/conf.py +++ b/gitbuildsys/conf.py @@ -169,6 +169,8 @@ class BrainConfigParser(SafeConfigParser): try: SafeConfigParser.set(self, section, option, value) + if replace_opt: + SafeConfigParser.remove_option(self, section, replace_opt) except NoSectionError, err: raise errors.ConfigError(str(err)) @@ -273,7 +275,6 @@ distconf = $build__distconf def __init__(self, fpath=None): self.cfgparser = BrainConfigParser() self.reset_from_conf(fpath) - self.replaced_keys = defaultdict(list) def reset_from_conf(self, fpath): if fpath: @@ -288,8 +289,6 @@ distconf = $build__distconf if not self._new_conf(): msger.error('No config file available') - self.replaced_keys = defaultdict(list) - if fpaths: try: self.cfgparser.read(fpaths) @@ -363,6 +362,7 @@ distconf = $build__distconf return True def _check_passwd(self): + replaced_keys = False for sec in self.DEFAULTS.keys(): for key in self.options(sec): if key.endswith('passwd'): @@ -370,12 +370,12 @@ distconf = $build__distconf if plainpass is None: continue # empty string password is acceptable here - self.replaced_keys[sec].append(key) + replaced_keys = True self.set(key, base64.b64encode(plainpass.encode('bz2')), sec) - if self.replaced_keys: + if replaced_keys: msger.warning('plaintext password in config file will ' 'be replaced by encoded one') self.update() @@ -406,11 +406,7 @@ distconf = $build__distconf def options(self, section='general'): try: - opts = self.cfgparser.options(section) - if section in self.replaced_keys: - opts = list(set(opts) - set(self.replaced_keys[section])) - - return opts + return self.cfgparser.options(section) except NoSectionError: if section in self.DEFAULTS: