Change error message showed to user.
authorHuang Hao <hao.h.huang@intel.com>
Thu, 13 Sep 2012 12:39:06 +0000 (20:39 +0800)
committerHuang Hao <hao.h.huang@intel.com>
Thu, 13 Sep 2012 12:39:06 +0000 (20:39 +0800)
- show user the correct message if section name specified by
    general.profile does not exist
- remove default value of remotebuild.build_server in code. if
    there is no [remotebuild] section in config file, gbs rb will
    do remote build with tizen.org. It's wried to user.
- complain no obs api found when running gbs rb, do not complain
    when parsing config file.

Change-Id: I7766a7ee04eec3e992e450aa26d0263ee45311fe

gitbuildsys/conf.py
tests/test_profile.py
tests/testdata/ini/empty_profile.ini [new file with mode: 0644]

index 547e02e3b90b762645f52d72c57fa0499f08090b..28522713c64eed4795b2d6223f88d6ce7cda0378 100644 (file)
@@ -188,11 +188,6 @@ class ConfigMgr(object):
                 'upstream_tag': 'upstream/%(upstreamversion)s',
                 'squash_patches_until': '',
             },
-            'remotebuild': {
-                'build_server': 'https://api.tizen.org',
-                'user':         '',
-                'passwd':       '',
-            },
             'build': {
                 'build_cmd':    '/usr/bin/build',
                 'distconf':     '/usr/share/gbs/tizen-1.0.conf',
@@ -359,6 +354,13 @@ url = http://download.tizen.org/snapshots/trunk/common/latest/
 
         return options
 
+    def has_section(self, section):
+        'indicate whether a section exists'
+        for parser in self._cfgparsers:
+            if parser.has_section(section):
+                return True
+        return False
+
     def get(self, opt, section='general'):
         'get item value. return plain text of password if item is passwd'
         if opt == 'passwd':
@@ -552,8 +554,10 @@ class BizConfigManager(ConfigMgr):
     def _build_profile_by_name(self, name):
         '''return profile object by a given section'''
         if not name.startswith('profile.'):
-            raise msger.error('profile section name must start '
-                              'with "profile.": %s' % name)
+            raise errors.ConfigError('section name specified by general.profile '
+                'must start with string "profile.": %s' % name)
+        if not self.has_section(name):
+            raise errors.ConfigError('no such section: %s' % name)
 
         user = self.get_optional_item(name, 'user')
         password = self.get_optional_item(name, 'passwd')
@@ -563,8 +567,8 @@ class BizConfigManager(ConfigMgr):
         obs = self.get_optional_item(name, 'obs')
         if obs:
             if not obs.startswith('obs.'):
-                msger.error('obs section name should start '
-                            'with "obs.": %s' % obs)
+                raise errors.ConfigError('obs section name should start '
+                                         'with string "obs.": %s' % obs)
 
             obsconf = OBSConf(profile, obs,
                               self._get_url_options(obs),
@@ -577,8 +581,8 @@ class BizConfigManager(ConfigMgr):
             for repo in repos.split(','):
                 repo = repo.strip()
                 if not repo.startswith('repo.'):
-                    msger.warning('repo section name should start '
-                                  'with "repo.": %s' % repo)
+                    msger.warning('ignore %s, repo section name should start '
+                                  'with string "repo."' % repo)
                     continue
 
                 repoconf = RepoConf(profile, repo,
@@ -628,19 +632,20 @@ class BizConfigManager(ConfigMgr):
         profile = Profile('profile.current', None, None)
 
         sec = 'remotebuild'
-        addr = self.get('build_server', sec)
-        user = self.get_optional_item(sec, 'user')
-        password = self.get_optional_item(sec, 'passwd')
+        addr = self.get_optional_item(sec, 'build_server')
+        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))
+            try:
+                url = SafeURL(addr, user, password)
+            except ValueError, err:
+                raise errors.ConfigError('%s for %s' % (str(err), addr))
 
-        obsconf = OBSConf(profile, 'obs.%s' % sec, url,
-                          self.get_optional_item('remotebuild', 'base_prj'),
-                          self.get_optional_item('remotebuild', 'target_prj'))
-        profile.set_obs(obsconf)
+            obsconf = OBSConf(profile, 'obs.%s' % sec, url,
+                              self.get_optional_item('remotebuild', 'base_prj'),
+                              self.get_optional_item('remotebuild', 'target_prj'))
+            profile.set_obs(obsconf)
 
         repos = self._parse_build_repos()
         for key, item in repos:
index 4efef9ad6f829c171a115a631ce84fad6964aa78..c7cf8638e78c1e14a7324f2051e4e4792f8c5b38 100644 (file)
@@ -21,6 +21,7 @@ import unittest
 from mock import patch, MagicMock, Mock
 
 import gitbuildsys.conf
+from gitbuildsys.errors import ConfigError
 from test_config import Fixture
 from test_passwdx import FakeFile
 
@@ -74,8 +75,14 @@ class ProfileStyleTest(unittest.TestCase):
 
     @Fixture(home='no_such_profile_section_name.ini')
     def test_no_such_profile(self):
-        'test get a empty profile when name does not exist'
+        'test profile name does not exist'
+        self.assertRaises(ConfigError, get_profile)
+
+    @Fixture(home='empty_profile.ini')
+    def test_empty_profile(self):
+        'test get a empty profile'
         profile = get_profile()
+
         self.assertEquals(None, profile.obs)
         self.assertEquals([], profile.repos)
 
diff --git a/tests/testdata/ini/empty_profile.ini b/tests/testdata/ini/empty_profile.ini
new file mode 100644 (file)
index 0000000..e9f1ab3
--- /dev/null
@@ -0,0 +1,4 @@
+[general]
+profile = profile.test
+
+[profile.test]
\ No newline at end of file