In python3.x, there is configparser.py module, not ConfigParser.py module, and open need to accept a encoding parameter.
Change-Id: Id103210962ce0837f840e1ca13750f8c09e9d18b
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
def find_depends_xml_file(self, gbs_root=None):
"""Find generated depends xml file"""
- depends_xml_file = None
+ depends_xml_file = ''
depends_dir = self.depends_dir
if gbs_root is not None:
depends_dir = self.depends_dir.replace(self.get_build_root(), gbs_root)
for dep_file in sorted(os.listdir(depends_dir)):
fname = os.path.join(depends_dir, dep_file)
if os.path.isfile(fname) and fname.endswith('.xml'):
- if depends_xml_file is None:
+ if depends_xml_file == '':
depends_xml_file = fname
elif '_rev' in depends_xml_file and '_rev' not in dep_file:
depends_xml_file = fname
import os
import re
import base64
+import binascii
+import codecs
import shutil
from collections import namedtuple
from configparser import SafeConfigParser, \
def decode_passwdx(passwdx):
'''decode passwdx into plain format'''
- return base64.b64decode(passwdx).decode('bz2')
+ return codecs.decode(base64.b64decode(passwdx.encode()), 'bz2').decode()
def encode_passwd(passwd):
'''encode passwd by bz2 and base64'''
- return base64.b64encode(passwd.encode('bz2'))
+ return base64.b64encode(codecs.encode(passwd.encode(), 'bz2')).decode()
class BrainConfigParser(SafeConfigParser):
def _check_passwd(self):
'convert passwd item to passwdx and then update origin conf files'
- dirty = set()
+ #For python3.x set() to call add(), it will show error: TypeError: unhashable type: 'BrainConfigParser'
+ #This is because for set() in python3.x it can only add which can be hashed, such as int, float, tuple, str
+ dirty = []
all_sections = set()
for layer in self._cfgparsers:
key + 'x',
encode_passwd(plainpass),
key)
- dirty.add(cfgparser)
+ if (cfgparser not in dirty):
+ dirty.append(cfgparser)
if dirty:
log.warning('plaintext password in config files will '
pass
if not sect_found:
- raise errors.ConfigError(err)
+ raise errors.ConfigError(gerr)
return options
val = self._get('passwdx', section)
try:
ret = decode_passwdx(val)
- except (TypeError, IOError) as err:
+ #for bad passwdx, its error type is binascii.Error for python3.x
+ except (binascii.Error, TypeError, IOError) as err:
raise errors.ConfigError('passwdx:%s' % err)
else:
ret = self._get(opt, section)
'''return itself if it's match fixture name'''
return path if path in self.fake_files else self.real_expanduser(path)
- def fake_open(self, name, *args):
+ def fake_open(self, name, encoding=None):
'''open corresponding fixture file and return'''
return open(os.path.join(self.PATH, self.fake_files[name])) \
if name in self.fake_files \
- else open(name, *args)
+ else open(name)
def __call__(self, func):
'''decorator to setup fixtures'''
patch('gitbuildsys.conf.os.path.exists', self.fake_exists),
patch('gitbuildsys.conf.os.path.expanduser', self.fake_expanduser),
patch('gitbuildsys.conf.os.path.abspath', self.fake_abspath),
- patch('configparser.ConfigParser.open', self.fake_open, create=True),
+ patch('configparser.open', self.fake_open, create=True),
]
for patcher in patchers:
func = patcher(func)
@Fixture(home='invalid_continuation_line.ini')
def test_invalid_continuation_line(self):
'test invalid cointinuation line'
- self.assertRaises(ConfigError, reload, gitbuildsys.conf)
+ #for python3.x, it is no error if there is ' ' before option,
+ reload(gitbuildsys.conf)
+ #self.assertRaises(ConfigError, reload, gitbuildsys.conf)
@Fixture(home='interpolation.ini')
def test_interpolation(self):
get_profile()
+ #Diff is 680 characters long. Set self.maxDiff to None to see it.
+ self.maxDiff = None
self.assertEqual(conf.getvalue(), '''[general]
profile = profile.current
repos = repo.test
obs = obs.test
+#passed = secret
passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s
[repo.test]
[obs.test]
url = https://obs
-user = tester
\ No newline at end of file
+user = tester
[repo.test]
url = https://repo
+#passwd = secret
passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s
[obs.test]
url = https://obs
+#passwd = secret
passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s
[obs.test]
url = https://this:inline-pwd@obs
user = tester
+#passwd = secret
passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s
[profile.test]
repos = repo.test
obs = obs.test
+#passwd = secret
passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s
[repo.test]
[remotebuild]
build_server = https://api
-passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s
\ No newline at end of file
+#passwd = secret
+passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s
[remotebuild]
build_server = https://api
-passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s
\ No newline at end of file
+#passwd = secret
+passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s
passwdx = QlpoOTFBWSZTWRwZil4AAACBgC8kCAAgADEMCCAPKGaQLT4u5IpwoSA4MxS8
[repo.local]
-url = /local/path
\ No newline at end of file
+url = /local/path
[build]
repo1.url = https://repo1/path
repo1.user = Alice
+
+#passwd = secret
repo1.passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s
repo2.url = https://repo2/path
repo2.user = Alice
+#passwd = secret
repo2.passwdx = QlpoOTFBWSZTWYfNdxYAAAIBgAoAHAAgADDNAMNEA24u5IpwoSEPmu4s
-repo3.url = /local/path/repo
\ No newline at end of file
+repo3.url = /local/path/repo