Add error handle for permission of obs project
authorZhang Qiang <qiang.z.zhang@intel.com>
Mon, 14 May 2012 02:56:54 +0000 (10:56 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Mon, 14 May 2012 02:56:54 +0000 (10:56 +0800)
gitbuildsys/buildservice.py
gitbuildsys/cmd_remotebuild.py

index f5f399f..1220205 100644 (file)
@@ -26,6 +26,7 @@ import time
 import urlparse
 import urllib2
 import xml.etree.cElementTree as ElementTree
+import errors
 from osc import conf, core
 
 class ObsError(Exception):
@@ -1132,7 +1133,10 @@ class BuildService(object):
         pac_path = os.path.basename(os.path.normpath(pac.absdir))
         files = {}
         files[pac_path] = pac.todo
-        core.Project(prj).commit(tuple([pac_path]), msg=msg, files=files)
+        try:
+            core.Project(prj).commit(tuple([pac_path]), msg=msg, files=files)
+        except urllib2.HTTPError, e:
+            raise errors.ObsError('%s' % e)   
         core.store_unlink_file(pac.absdir, '_commit_msg')
 
     def branchPkg(self, src_project, src_package, rev=None, target_project=None, target_package=None):
index 5d6971c..36965df 100644 (file)
@@ -105,6 +105,9 @@ def do(opts, args):
     prj = obspkg.ObsProject(target_prj, apiurl = APISERVER, oscrc = oscrcpath)
     msger.info('checking status of obs project: %s ...' % target_prj)
     if prj.is_new():
+        if opts.target_obsprj and not target_prj.startswith('home:%s:' % USER):
+            msger.error('no permission to create project %s, only subpackage '\
+                        'of home:%s is allowed ' % (target_prj, USER))
         msger.info('creating %s for package build ...' % target_prj)
         try:
             prj.branch_from(base_prj)
@@ -129,8 +132,12 @@ def do(opts, args):
 
     localpkg.update_local()
 
-    msger.info('commit packaging files to build server ...')
-    localpkg.commit ('submit packaging files to obs for OBS building')
+    try:
+        msger.info('commit packaging files to build server ...')
+        localpkg.commit ('submit packaging files to obs for OBS building')
+    except errors.ObsError, e:
+        msger.error('commit packages fail: %s, please check the permission '\
+                    'of target project:%s' % (e,target_prj))
 
     os.unlink(oscrcpath)
     msger.info('local changes submitted to build server successfully')