From 77547118731f08e4e1b60729d700b6b0183ec91c Mon Sep 17 00:00:00 2001 From: Zhang Qiang Date: Mon, 2 Jul 2012 14:24:31 +0800 Subject: [PATCH] add --buildlog and --results support for gbs remotebuild --- gitbuildsys/buildservice.py | 34 +++++++++++++++++++++------ gitbuildsys/cmd_remotebuild.py | 53 ++++++++++++++++++++++++++++++++++++++---- tools/gbs | 11 +++++++++ 3 files changed, 87 insertions(+), 11 deletions(-) diff --git a/gitbuildsys/buildservice.py b/gitbuildsys/buildservice.py index 1be16ca..78e57f0 100644 --- a/gitbuildsys/buildservice.py +++ b/gitbuildsys/buildservice.py @@ -20,12 +20,17 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import os +import string +import sys import shutil import tempfile import time import urlparse import urllib2 +import M2Crypto import xml.etree.cElementTree as ElementTree +from collections import defaultdict + import errors from osc import conf, core @@ -298,7 +303,8 @@ class BuildService(object): new_prj = True else: raise errors.ObsError("%s" % e) - except urllib2.URLError, e: + except (urllib2.URLError, M2Crypto.m2urllib2.URLError, \ + M2Crypto.SSL.SSLError), e: raise errors.ObsError("%s" % e) return new_prj @@ -1171,12 +1177,6 @@ class BuildService(object): def get_buildconfig(self, prj, repository): return core.get_buildconfig(self.apiurl, prj, repository) - def get_repos(self, prj): - repos = [] - for repo in core.get_repos_of_project(self.apiurl, prj): - repos.append(repo) - return repos - def get_ArchitectureList(self, prj, target): """ return the list of Archictecture of the target of the projectObsName for a OBS server. @@ -1194,3 +1194,23 @@ class BuildService(object): return result + def get_results(self, prj, package): + try: + results = defaultdict(dict) + build_status = core.get_results(self.apiurl, prj, package) + for res in build_status: + repo, arch, status = res.split() + results[repo][arch] = status + return results + except (M2Crypto.m2urllib2.URLError, M2Crypto.SSL.SSLError), err: + raise errors.ObsError(str(err)) + + def get_buildlog(self, prj, package, repository, arch, offset = 0): + """prints out the buildlog on stdout""" + all_bytes = string.maketrans('', '') + remove_bytes = all_bytes[:10] + all_bytes[11:32] + try: + log = self.getBuildLog(prj, '%s/%s' % (repository, arch), package) + sys.stdout.write(log.translate(all_bytes, remove_bytes)) + except (M2Crypto.m2urllib2.URLError, M2Crypto.SSL.SSLError), err: + raise errors.ObsError(str(err)) diff --git a/gitbuildsys/cmd_remotebuild.py b/gitbuildsys/cmd_remotebuild.py index 29d5254..24ceb09 100644 --- a/gitbuildsys/cmd_remotebuild.py +++ b/gitbuildsys/cmd_remotebuild.py @@ -26,6 +26,7 @@ import shutil import msger from conf import configmgr +import buildservice import obspkg import errors import utils @@ -53,11 +54,24 @@ PASSWDX = configmgr.get('passwdx', 'remotebuild') def do(opts, args): - workdir = os.getcwd() - if len(args) > 1: - msger.error('only one work directory can be specified in args.') - if len(args) == 1: + obs_repo = None + obs_arch = None + + if len(args) == 0: + workdir = os.getcwd() + elif len(args) == 1: + workdir = os.path.abspath(args[0]) + elif len(args) == 2 and opts.buildlog: + workdir = os.getcwd() + obs_repo = args[0] + obs_arch = args[1] + elif len(args) == 3 and opts.buildlog: workdir = os.path.abspath(args[0]) + obs_repo = args[1] + obs_arch = args[2] + else: + msger.error('Invalid arguments, see gbs remotebuild -h for more info') + try: repo = RpmGitRepository(workdir) except GitRepositoryError: @@ -110,6 +124,37 @@ def do(opts, args): else: target_prj = opts.target_obsprj + if opts.buildlog: + bs = buildservice.BuildService(apiurl=APISERVER, oscrc=oscrcpath) + archlist = [] + status = bs.get_results(target_prj, spec.name) + for repository in status.keys(): + for arch in status[repository]: + archlist.append('%-15s%-15s' % (repository, arch)) + if not obs_repo or not obs_arch or obs_repo not in status.keys() or \ + obs_arch not in status[obs_repo].keys(): + msger.info('please specify correct repo / arch for buildlog') + msger.info('valid arguments of repo and arch are:\n%s' % \ + '\n'.join(archlist)) + return 1 + if status[obs_repo][obs_arch] not in ['failed', 'succeeded', \ + 'building']: + msger.error('build status of %s for %s/%s is %s, no build log.' % \ + (spec.name, obs_repo, obs_arch, status[obs_repo][obs_arch])) + bs.get_buildlog(target_prj, spec.name, obs_repo, obs_arch) + return 0 + + if opts.status: + bs = buildservice.BuildService(apiurl=APISERVER, oscrc=oscrcpath) + results = [] + status = bs.get_results(target_prj, spec.name) + for repository in status.keys(): + for arch in status[repository]: + stat = status[repository][arch] + results.append('%-15s%-15s%-15s' % (repository, arch, stat)) + msger.info('build results from build server:\n%s' % '\n'.join(results)) + return 0 + prj = obspkg.ObsProject(target_prj, apiurl = APISERVER, oscrc = oscrcpath) msger.info('checking status of obs project: %s ...' % target_prj) if prj.is_new(): diff --git a/tools/gbs b/tools/gbs index 784ceee..40f070c 100755 --- a/tools/gbs +++ b/tools/gbs @@ -239,6 +239,17 @@ class Gbs(cmdln.Cmdln): default=None, dest='commit', help='Specify a commit ID to build') + @cmdln.option('--buildlog', + action='store_true', + default=False, + dest='buildlog', + help='Get buildlog from build sever') + @cmdln.option('--status', + action='store_true', + default=False, + dest='status', + help='Get build status from build server') + def do_remotebuild(self, subcmd, opts, *args): """${cmd_name}: remote build package -- 2.7.4