from __future__ import with_statement
import os, sys
import base64
+from collections import defaultdict
from ConfigParser import *
import msger
import errors
distconf = $build__distconf
; optional, repos definitions
-repo1.url=
-repo1.user=
-repo1.passwdx=
-repo2.url=
-repo2.user=
-repo2.passwdx=
+# repo1.url=
+# repo1.user=
+# repo1.passwd=
+; one more repo
+# repo2.url=
+# repo2.user=
+# repo2.passwd=
[import]
; optional, for git author information
msger.error('No config file available')
self.cfgparser.read(fpaths)
+
+ self.replaced_keys = defaultdict(list)
self._check_passwd()
def _lookfor_confs(self):
def _check_passwd(self):
for sec in self.DEFAULTS.keys():
- if 'passwd' in self.DEFAULTS[sec]:
- plainpass = self._get('passwd', sec)
- if not plainpass:
- # None or ''
- continue
-
- msger.warning('plaintext password in config file will '
- 'be replaced by encoded one')
- self.set('passwd',
- base64.b64encode(plainpass.encode('bz2')),
- sec)
- self.update()
+ for key in self.options(sec):
+ if key.endswith('passwd'):
+ plainpass = self._get(key, sec)
+ if not plainpass:
+ # None or ''
+ continue
+
+ self.replaced_keys[sec].append(key)
+ self.set(key,
+ base64.b64encode(plainpass.encode('bz2')),
+ sec)
+
+ if self.replaced_keys:
+ msger.warning('plaintext password in config file will '
+ 'be replaced by encoded one')
+ self.update()
def _get(self, opt, section='general'):
try:
def options(self, section='general'):
try:
- return self.cfgparser.options(section)
+ opts = self.cfgparser.options(section)
+ if section in self.replaced_keys:
+ opts = list(set(opts) - set(self.replaced_keys[section]))
+
+ return opts
+
except NoSectionError:
if section in self.DEFAULTS:
return self.DEFAULTS[section]
return self._get(opt, section)
def set(self, opt, val, section='general', replace_opt=None):
- if opt == 'passwd':
- opt = 'passwdx'
- replace_opt = 'passwd'
+ if opt.endswith('passwd'):
+ replace_opt = opt
+ opt += 'x'
return self.cfgparser.set(section, opt, val, replace_opt)
def update(self):