More error handling with gbs conf
authorZhang Qiang <qiang.z.zhang@intel.com>
Wed, 27 Jun 2012 08:27:50 +0000 (16:27 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Wed, 27 Jun 2012 08:27:50 +0000 (16:27 +0800)
gitbuildsys/cmd_build.py
gitbuildsys/conf.py
tools/gbs

index ecb71a9..f1b4f2b 100644 (file)
@@ -180,10 +180,10 @@ def get_reops_conf():
             try:
                 (name, key) = opt.split('.')
             except ValueError:
-                raise Exception("Invalid repo option: %s" % opt)
+                raise errors.ConfigError("invalid repo option: %s" % opt)
             else:
                 if key not in ('url', 'user', 'passwdx'):
-                    raise Exception("Invalid repo option: %s" % opt)
+                    raise errors.ConfigError("invalid repo option: %s" % opt)
                 repos.add(name)
 
     # get repo settings form build section
index 8dc99a3..41b5107 100644 (file)
@@ -147,7 +147,7 @@ class BrainConfigParser(SafeConfigParser):
 
         # if any parsing errors occurred, raise an exception
         if exc:
-            raise exc
+            raise errors.ConfigError(str(exc))
 
     def set(self, section, option, value, replace_opt=None):
         """When set new value, need to update the readin file lines,
@@ -171,7 +171,10 @@ class BrainConfigParser(SafeConfigParser):
             # if reach here, sec is the last one
             return -1
 
-        SafeConfigParser.set(self, section, option, value)
+        try:
+            SafeConfigParser.set(self, section, option, value)
+        except NoSectionError, err:
+            raise errors.ConfigError(str(err))
 
         # If the code reach here, it means the section and key are ok
         if replace_opt is None:
index d99c2b7..c6c1d41 100755 (executable)
--- a/tools/gbs
+++ b/tools/gbs
@@ -21,7 +21,6 @@ import re
 
 from gitbuildsys.__version__ import VERSION
 from gitbuildsys import msger, cmdln, errors
-from gitbuildsys.conf import configmgr
 
 def handle_repository(option, opt_str, value, parser):
     if not value:
@@ -326,6 +325,7 @@ class Gbs(cmdln.Cmdln):
 
 if __name__ == '__main__':
     try:
+        from gitbuildsys.conf import configmgr
         sys.exit(Gbs().main())
 
     except KeyboardInterrupt: