Implemented --showurls option
authorEd Bartosh <eduard.bartosh@intel.com>
Mon, 7 Apr 2014 13:12:48 +0000 (16:12 +0300)
committerEd Bartosh <eduard.bartosh@intel.com>
Fri, 11 Apr 2014 09:49:02 +0000 (12:49 +0300)
Some users want to see urls in repa list output. It's inconvenient for
them to use repa info for every submission to see the urls.

Fixes: #1789

Change-Id: I7cc31bc327fc9593ab21efdd85fe4fe6accfd544
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
repa.1
repa/common.py
repa/info.py
repa/list.py

diff --git a/repa.1 b/repa.1
index b0b6aa5..d438e12 100644 (file)
--- a/repa.1
+++ b/repa.1
@@ -87,7 +87,7 @@ Turn on colorized output
 .\"
 .\" The "list" command description
 .\"
-.SS \fBlist\fR [\-\-help] [\-\-processes <processes>]
+.SS \fBlist\fR [\-\-help] [\-\-processes <processes>] [\-\-showurls]
 
 .RS 2
 List submissions in the following format:
@@ -128,9 +128,16 @@ PROCESSES
 .RS 2
 Use PROCESSES to specify the amount of python processes to run in parallel. Usage of this option can significantly speed up repa list.
 Note, that this parameter can also be specified in \fIrepa\fR configuration file.
+.RE
 
+.PP
+.B \-\-showurls
+.RS 2
+Show OBS and download urls in the output. It's switched off by default.
+Note, that this parameter can also be specified in \fIrepa\fR configuration file.
 .RE
 
+
 .PP
 .\"
 .\" The "info" command description
@@ -319,13 +326,17 @@ project = Tizen:IVI
 .RS 2
 color = off
 .RE
+.RS 2
+showurls = off
+.RE
+
 
 .RS 2
 Mandatory options: apiurl, apiuser, apipasswd and project
 .RE
 
 .RS 2
-Some options (project, processes, colorize) can be overridden by commandline options (--project, --processes, --colorize)
+Some options (project, processes, colorize, showurls) can be overridden by commandline options (--project, --processes, --colorize, --showurls)
 .RE
 
 .SH BUGS
index 622b47e..79d6ed7 100644 (file)
@@ -30,6 +30,7 @@ Common functions, classes, exceptions.
 """
 
 import sys
+import os
 import time
 import json
 from functools import wraps, partial
@@ -180,3 +181,28 @@ class Colorizer:
         else:
             return text
 
+def get_download_url(meta):
+    """Get download url from meta."""
+    if 'download_url' in meta:
+        return meta['download_url']
+    # Guess url from image url if download_url is not in the meta
+    if 'images' not in meta:
+        return
+    for img in meta['images']:
+        if 'url' in img:
+            return img['url'].split('images')[0]
+
+
+def get_obs_url(meta, buildurl='https://build.tizen.org'):
+    """Get obs project url from meta."""
+    if 'obs_url' in meta:
+        return meta['obs_url']
+    # Make it from git tag and obs_target_prj if obs_url is not in the meta
+    if 'obs_target_prj' not in meta:
+        return
+    if 'name' not in meta and 'git_tag' not in meta:
+        return
+    name = meta.get('git_tag') or meta.get('name')
+    return os.path.join(buildurl, 'project/show?project=home:prerelease:%s:%s'
+                        % (meta['obs_target_prj'], name.replace('/', ':')))
+
index 7de8739..267d8e3 100755 (executable)
@@ -34,7 +34,7 @@ import os
 
 from collections import defaultdict
 
-from repa.common import get_project_by_name
+from repa.common import get_project_by_name, get_download_url, get_obs_url
 from repa.obs import OBS
 
 from repa.main import sub_main
@@ -52,32 +52,6 @@ def get_status(results):
     return status
 
 
-def get_download_url(meta):
-    """Get download url from meta."""
-    if 'download_url' in meta:
-        return meta['download_url']
-    # Guess url from image url if download_url is not in the meta
-    if 'images' not in meta:
-        return
-    for img in meta['images']:
-        if 'url' in img:
-            return img['url'].split('images')[0]
-
-
-def get_obs_url(meta, buildurl='https://build.tizen.org'):
-    """Get obs project url from meta."""
-    if 'obs_url' in meta:
-        return meta['obs_url']
-    # Make it from git tag and obs_target_prj if obs_url is not in the meta
-    if 'obs_target_prj' not in meta:
-        return
-    if 'name' not in meta and 'git_tag' not in meta:
-        return
-    name = meta.get('git_tag') or meta.get('name')
-    return os.path.join(buildurl, 'project/show?project=home:prerelease:%s:%s'
-                        % (meta['obs_target_prj'], name.replace('/', ':')))
-
-
 def info(obs, name, target):
     """Print detailed info about submission or submitgroup."""
     is_group = name.startswith('submitgroup/')
index 4f358bd..ace70e9 100755 (executable)
@@ -32,7 +32,8 @@ Get list of submissions.
 import sys
 import json
 
-from repa.common import OBS_PROJECT_PREFIX, Colorizer
+from repa.common import (OBS_PROJECT_PREFIX, Colorizer,
+                         get_download_url, get_obs_url)
 from repa.obs import OBS
 from repa.main import sub_main
 
@@ -65,7 +66,19 @@ def get_status(meta, colorizer, build_results=None):
     return colorizer.green('ready')
 
 
-def list_submissions(obs, target, processes, is_colorize=False):
+def show_urls(meta):
+    """Print OBS and download urls."""
+    download_url = get_download_url(meta)
+    if download_url:
+        print '    download url: ', download_url
+    obs_url = get_obs_url(meta)
+    if obs_url:
+        print '    obs url: ', obs_url
+    print
+
+
+def list_submissions(obs, target, processes, is_colorize=False,
+                     showurls=False):
     """List submissions and groups."""
     colorizer = Colorizer(is_colorize)
     # submissions
@@ -80,12 +93,16 @@ def list_submissions(obs, target, processes, is_colorize=False):
         projects = [project.split('/')[-1] for project in meta['projects']]
         print '%-37s %-37s %s' % (meta['git_tag'], \
               get_status(meta, colorizer, build_results), ','.join(projects))
+        if showurls:
+            show_urls(meta)
 
     # groups
     if groups:
         print
         for meta in groups:
             print '%-37s %-37s' % (meta['name'], get_status(meta, colorizer))
+            if showurls:
+                show_urls(meta)
 
 
 class List(object):
@@ -104,13 +121,16 @@ class List(object):
         parser.add_argument('--processes', type=int,
                             help='amount of parallel processes to use',
                             default=config.get('processes'))
+        parser.add_argument('--showurls', action='store_true',
+                            help='show OBS and download urls',
+                            default=config.get('showurls', '').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.colorize)
+                                argv.colorize, argv.showurls)
 
 
 if __name__ == '__main__':