import ast
import base64
import shutil
+from collections import namedtuple
from ConfigParser import SafeConfigParser, NoSectionError, \
MissingSectionHeaderError, Error
else:
return self._get(opt, section)
- def update(self, cfgparsers):
+ @staticmethod
+ def update(cfgparsers):
'update changed values into files on disk'
for cfgparser in cfgparsers:
try:
msger.warning('update config file error: %s' % err)
+URL = namedtuple('URL', 'url user password')
+
+
class OBSConf(object):
'Config items related to obs section'
def __init__(self, parent, name, url, base, target):
self.parent = parent
self.name = name
- self.url = url
self.base = base
self.target = target
+ user = url.user or parent.common_user
+ password = url.password or parent.common_password
+ try:
+ self.url = SafeURL(url.url, user, password)
+ except ValueError, err:
+ raise errors.ConfigError('%s for %s' % (str(err), url.url))
+
def dump(self, fhandler):
'dump ini to file object'
parser = BrainConfigParser()
def __init__(self, parent, name, url):
self.parent = parent
self.name = name
- self.url = url
+
+ user = url.user or parent.common_user
+ password = url.password or parent.common_password
+ try:
+ self.url = SafeURL(url.url, user, password)
+ except ValueError, err:
+ raise errors.ConfigError('%s for %s' % (str(err), url.url))
def dump(self, fhandler):
'dump ini to file object'
self.repos = []
self.obs = None
- def _update_url(self, url):
- 'update url by common auth info'
- if not url.user:
- url.user = self.common_user
- if not url.passwd:
- url.passwd = self.common_password
- return url
-
def add_repo(self, repoconf):
'''add a repo to repo list of the profile'''
- self._update_url(repoconf.url)
self.repos.append(repoconf)
def set_obs(self, obsconf):
'''set OBS api of the profile'''
- self._update_url(obsconf.url)
self.obs = obsconf
def dump(self, fhandler):
url = self.get('url', section_id)
user = self.get_optional_item(section_id, 'user')
password = self.get_optional_item(section_id, 'passwd')
- try:
- return SafeURL(url, user, password)
- except ValueError, err:
- raise errors.ConfigError('%s for %s' % (str(err), url))
+ return URL(url, user, password)
def _build_profile_by_name(self, name):
'''return profile object by a given section'''
if addr:
user = self.get_optional_item(sec, 'user')
password = self.get_optional_item(sec, 'passwd')
-
- try:
- url = SafeURL(addr, user, password)
- except ValueError, err:
- raise errors.ConfigError('%s for %s' % (str(err), addr))
+ url = URL(addr, user, password)
obsconf = OBSConf(profile, 'obs.%s' % sec, url,
self.get_optional_item('remotebuild', 'base_prj'),
for key, item in repos:
if 'url' not in item:
raise errors.ConfigError("URL is not specified for %s" % key)
- try:
- url = SafeURL(item['url'], item.get('user'), item.get('passwd'))
- except ValueError, err:
- raise errors.ConfigError('%s for %s' % (str(err), item['url']))
+ url = URL(item['url'], item.get('user'), item.get('passwd'))
repoconf = RepoConf(profile, 'repo.%s' % key, url)
profile.add_repo(repoconf)
self.assertEquals('https://Bob:classified@repo/ia32/base',
get_profile().repos[2].url.full)
+ @Fixture(home='bug387_inherit_only_user.ini')
+ def test_inherit_only_user(self):
+ 'test inherit only user from parent'
+ self.assertEquals('https://tester:secret@repo',
+ get_profile().repos[0].url.full)
+ self.assertEquals('https://tester:secret@obs',
+ get_profile().obs.url.full)
+
+ @Fixture(home='bug387_inherit_only_passwdx.ini')
+ def test_inherit_only_passwdx(self):
+ 'test inherit only password from parent'
+ self.assertEquals('https://tester:secret@repo',
+ get_profile().repos[0].url.full)
+ self.assertEquals('https://tester:secret@obs',
+ get_profile().obs.url.full)
+
+ @Fixture(home='bug387_only_password_no_user.ini')
+ def test_only_password_no_user(self):
+ 'test only password no user'
+ self.assertRaises(ConfigError, get_profile)
+
+ @Fixture(home='bug387_inline_auth_has_the_highest_priority.ini')
+ def test_inline_highest_priority(self):
+ 'test inline auth has the highest priority'
+ self.assertEquals('https://this:inline-pwd@obs',
+ get_profile().obs.url.full)
+
@Fixture(home='no_such_profile_section_name.ini')
def test_no_such_profile(self):
'test profile name does not exist'