repa list: Add build time
authorEd Bartosh <eduard.bartosh@intel.com>
Tue, 3 Feb 2015 18:55:30 +0000 (20:55 +0200)
committerEd Bartosh <eduard.bartosh@intel.com>
Thu, 5 Feb 2015 20:53:13 +0000 (22:53 +0200)
Added optional configuration and command line option to
show build time for the submissions in 'ready' status.

Fixes: #2325
Change-Id: Ieec61217aedec9a254e7b7695ff085eab5709b81
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
repa.1
repa/list.py
repa/obs.py

diff --git a/repa.1 b/repa.1
index 289e88e57f0957694006a2bb9bea901c73c97c00..3416d908d5d6337061e057f5f5aca7f58ed68da7 100644 (file)
--- a/repa.1
+++ b/repa.1
@@ -102,7 +102,7 @@ Turn on colorized output
 .\"
 .\" The "list" command description
 .\"
-.SS \fBlist\fR [\-\-help] [\-\-processes <processes>] [\-\-showurls] [\-\-ignore <regexp>] [\-\-base <project>]
+.SS \fBlist\fR [\-\-help] [\-\-processes <processes>] [\-\-showurls] [\-\-ignore <regexp>] [\-\-base <project>] [\-\-showtime]
 
 .RS 2
 List submissions in the following format:
@@ -119,9 +119,9 @@ submit/tizen/20140327.055105          package building       libav zlib
 .RS 0
 submit/tizen/20140327.080733          image building         bluez
 .RS 0
-submit/tizen/20140328.063916          ready                  connman
+submit/tizen/20140328.063916          ready 01:20:14         connman
 .RS 0
-submit/tizen/20140328.080409          ready                  sdbd
+submit/tizen/20140328.080409          ready 00:14:30         sdbd
 .RS 0
 
 .RE
@@ -166,6 +166,14 @@ Show status of the submission in the base project.
 Note, that this parameter can also be specified in \fIrepa\fR configuration file.
 .RE
 
+.PP
+.B \-\-showtime
+.RS 2
+Show submission build time for the submissions in 'ready' status. It's switched off by default.
+Note, that this parameter can also be specified in \fIrepa\fR configuration file.
+.RE
+
+
 .PP
 .\"
 .\" The "show" command description
@@ -531,6 +539,10 @@ ignore = arm-.*/armv7./.*_aggregate$
 .RS 2
 noaggregate = mic-bootstrap-x86-arm.rpm|mic-bootstrap.rpm|mic-bootstrap-debugsource.rpm|qemu-accel-armv7l.rpm|qemu-accel-armv7l-cross-arm.rpm|qemu-linux-user-cross-arm.rpm
 .RE
+.RS 2
+showtime = off
+.RE
+
 
 
 .RS 2
@@ -538,7 +550,7 @@ Mandatory options: apiurl, apiuser, apipasswd, jenkins_url, jenkins_user, jenkin
 .RE
 
 .RS 2
-Some options (project, processes, colorize, showurls, ignore, noaggregate, base) can be overridden by commandline options (--project, --processes, --colorize, --showurls, --ignore, --noaggregate, --base)
+Some options (project, processes, colorize, showurls, ignore, noaggregate, base, showtime) can be overridden by commandline options (--project, --processes, --colorize, --showurls, --ignore, --noaggregate, --base, --showtime)
 .RE
 
 .SH BUGS
index 0d19d9668583d003c75ac0b6b486ed12f8de7ad3..0e0251b772ab1f8cd8f02a4f28a0e1eebd146dd2 100755 (executable)
@@ -38,7 +38,8 @@ from repa.common import (OBS_PROJECT_PREFIX, Colorizer,
 from repa.obs import OBS
 from repa.main import sub_main
 
-def get_status(meta, colorizer, build_results=None, ignore=''):
+def get_status(meta, colorizer, build_results=None, ignore='',
+               obs=None, showtime=False):
     """Get overall status by analyzing package and image build status."""
     if build_results:
         codes = set()
@@ -71,7 +72,19 @@ def get_status(meta, colorizer, build_results=None, ignore=''):
     else:
         return colorizer.blue('waiting for images')
 
-    return colorizer.green('ready')
+    status = 'ready'
+    if obs and showtime:
+        # Add build time to the status
+        project = get_prerelease(meta['git_tag'], meta['obs_target_prj'])
+        btime = 0
+        for (repo, arch), target in build_results.iteritems():
+            btime = max(btime, obs.get_build_time(str(project), str(repo),
+                                                  str(arch)))
+        minutes, seconds = divmod(btime, 60)
+        hours, minutes = divmod(minutes, 60)
+        status += " %02d:%02d:%02d" % (hours, minutes, seconds)
+
+    return colorizer.green(status)
 
 
 def show_urls(meta):
@@ -93,7 +106,7 @@ def get_sr(obs, project, package, tag, status):
                 return sreq[0]
 
 def list_submissions(obs, target, processes, base, is_colorize=False,
-                     showurls=False, ignore=''):
+                     showurls=False, ignore='', showtime=False):
     """List submissions and groups."""
     colorizer = Colorizer(is_colorize)
     # submissions
@@ -123,15 +136,16 @@ def list_submissions(obs, target, processes, base, is_colorize=False,
                     rsr = get_sr(obs, base, projects[0], tag, 'revoked')
                     if rsr:
                         base_status = colorizer.red('rejected. SR %s' % rsr)
-
             print '%-37s %-37s %-37s %s' % \
                   (meta['git_tag'],
-                   get_status(meta, colorizer, build_results, ignore),
+                   get_status(meta, colorizer, build_results,
+                              ignore, obs, showtime),
                    base_status, ','.join(projects))
         else:
             print '%-37s %-37s %s' % \
                   (meta['git_tag'], \
-                   get_status(meta, colorizer, build_results, ignore),
+                   get_status(meta, colorizer, build_results,
+                              ignore, obs, showtime),
                    ','.join(projects))
         if showurls:
             show_urls(meta)
@@ -168,13 +182,17 @@ class List(object):
                             help='ignore package failures by regexp')
         parser.add_argument('--base', default=config.get('base', ''),
                             help='Show submission status in base project')
+        parser.add_argument('--showtime', action='store_true',
+                            help='show build time',
+                            default=config.get('showtime', '').lower() == 'on')
 
     @staticmethod
     def run(argv):
         """Command line entry point. Called from [sub_]main"""
         obs = OBS(argv.apiurl, argv.apiuser, argv.apipasswd)
         return list_submissions(obs, argv.project, argv.processes, argv.base,
-                                argv.colorize, argv.showurls, argv.ignore)
+                                argv.colorize, argv.showurls, argv.ignore,
+                                argv.showtime)
 
 
 if __name__ == '__main__':
index 572a639707fc38f4c730c4b9896093184a887013..d25017fe9c0beacd7cc36d01db76530fcb8fa3fa 100644 (file)
@@ -144,6 +144,17 @@ class OBS(OSC):
 
         return buildres
 
+    @retry((OSCError, HTTPError))
+    def get_build_time(self, prj, repo, arch):
+        """Get build time for the project/repo/arch."""
+        url = core.makeurl(self.apiurl,
+                           ['build', prj, repo, arch, '_jobhistory'])
+        history = self.core_http(core.http_GET, url)
+        history_root = ET.parse(history).getroot()
+        seconds = 0
+        for node in history_root.findall('jobhist'):
+            seconds += int(node.get('endtime')) - int(node.get('starttime'))
+        return seconds
 
     def get_source_packages(self, prj):
         """Get list of binary packages in the project."""