From c00751f4d78cab3ac21cbd366ce6643d8aaec75f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Tue, 24 May 2011 10:49:08 +0200 Subject: [PATCH] - handle errors of source service runs --- osc/commandline.py | 9 +++++++-- osc/core.py | 11 ++++++++--- osc/oscerr.py | 6 ++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index 8a5042bf..f7834248 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -4727,9 +4727,14 @@ Please submit there instead, or use --nodevelproject to force direct submission. args = self.parse_repoarchdescr(args, opts.noinit or opts.offline, opts.alternative_project) # check for source services - if not opts.noservice and not opts.noinit and os.listdir('.').count("_service"): + if not opts.noservice and not opts.noinit: p = Package('.') - p.run_source_services() + r = p.run_source_services() + if r != 0: + print >>sys.stderr, 'Source service run failed!' + sys.exit(1) + # that is currently unreadable on cli, we should not have a backtrace on standard errors: + #raise oscerr.ServiceRuntimeError('Service run failed: \'%s\'', r) if conf.config['no_verify']: opts.no_verify = True diff --git a/osc/core.py b/osc/core.py index a7b1ec2f..45bb9af4 100644 --- a/osc/core.py +++ b/osc/core.py @@ -317,6 +317,7 @@ class Serviceinfo: allservices = [data] # recreate files + ret = 0 for service in allservices: if singleservice and service['name'] != singleservice: continue @@ -332,12 +333,13 @@ class Serviceinfo: c = "/usr/lib/obs/service/" + call + " --outdir " + temp_dir if conf.config['verbose'] > 1: print "Run source service:", c - ret = subprocess.call(c, shell=True) - if ret != 0: + r = subprocess.call(c, shell=True) + if r != 0: print "ERROR: service call failed: " + c # FIXME: addDownloadUrlService calls si.execute after # updating _services. print " (your _services file may be corrupt now)" + ret = r if service['mode'] == "disabled" or service['mode'] == "trylocal" or service['mode'] == "localonly" or callmode == "local": for filename in os.listdir(temp_dir): @@ -347,6 +349,8 @@ class Serviceinfo: shutil.move( os.path.join(temp_dir, filename), os.path.join(dir, "_service:"+name+":"+filename) ) os.rmdir(temp_dir) + return ret + class Linkinfo: """linkinfo metadata (which is part of the xml representing a directory """ @@ -2045,8 +2049,9 @@ rev: %s service = ET.parse(os.path.join(self.absdir, '_service')).getroot() si.read(service) si.getProjectGlobalServices(self.apiurl, self.prjname, self.name) - si.execute(self.absdir, mode, singleservice) + r = si.execute(self.absdir, mode, singleservice) os.chdir(curdir) + return r def prepare_filelist(self): """Prepare a list of files, which will be processed by process_filelist diff --git a/osc/oscerr.py b/osc/oscerr.py index f523b92a..5429ddf6 100644 --- a/osc/oscerr.py +++ b/osc/oscerr.py @@ -48,6 +48,12 @@ class ExtRuntimeError(OscBaseError): self.msg = msg self.file = fname +class ServiceRuntimeError(OscBaseError): + """Exception raised when there is source service error runtime error""" + def __init__(self, msg): + OscBaseError.__init__(self) + self.msg = msg + class WrongArgs(OscBaseError): """Exception raised by the cli for wrong arguments usage"""