[PATCH 2/5] Rework the layout of the list command

Pierre-Yves Chibon pingou at pingoured.fr
Wed Nov 27 19:42:05 UTC 2013


Instead of the table that was getting completely twisted by large description, use
a more simpler tree/list type of layout.
---
 copr_cli/subcommands.py | 79 ++++++++++++++++---------------------------------
 1 file changed, 25 insertions(+), 54 deletions(-)

diff --git a/copr_cli/subcommands.py b/copr_cli/subcommands.py
index dc2ddb0..57da934 100644
--- a/copr_cli/subcommands.py
+++ b/copr_cli/subcommands.py
@@ -17,8 +17,8 @@ import copr_exceptions
 def get_user():
     """ Retrieve the user information from the config file. """
     config = ConfigParser.ConfigParser()
-    if not config.read(os.path.join(os.path.expanduser('~'), '.config',
-                'copr')):
+    if not config.read(
+            os.path.join(os.path.expanduser('~'), '.config', 'copr')):
         raise copr_exceptions.CoprCliNoConfException(
             'No configuration file "~/.config/copr" found.')
     try:
@@ -70,62 +70,33 @@ def listcoprs(username=None):
         return
 
     output = json.loads(req.text)
-    columns = []
-    values = []
+
     if 'repos' in output:
         if output['repos']:
-            columns = ['name', 'description', 'yum_repos', 'additional_repos', 'instructions']
-            values = []
-            for entry in output['repos']:
-                values.append([entry[key] for key in columns])
-        else:
-            columns = ['output']
-            values = ['No copr retrieved for user: "{0}"'.format(
-                user['username'])]
-    else:
-        columns = ['output']
-        values = ['Wrong output format returned by the server']
-
-    def _list_to_row(values, widths):
-        ''' Return a print ready version of the provided list '''
-        row = []
-        cnt = 0
-        for item in values:
-            max_width = widths[cnt]
-            cnt += 1
-            if not item:
-                item = ''
-            if cnt < len(values):
-                row.append(item.ljust(max_width + 1))
-            else:
-                row.append(item)
-        return row
-
-    if len(columns) > 1:
-        widths = {}
-        cnt = 0
-        for item in columns:
-            widths[cnt] = len(item)
-            cnt += 1
-        for row in values:
-            cnt = 0
-            for item in row:
-                if not item:
-                    item = ''
-                widths[cnt] = max(widths[cnt], len(item))
-                cnt += 1
-
-        headers = '|'.join(_list_to_row(columns, widths))
-        print headers
-        print '-' * len(headers)
-        for row in values:
-            print "|".join(_list_to_row(row, widths))
+            for repo in output['repos']:
+                print 'Name: {0}'.format(repo['name'])
+
+                if 'description' in repo:
+                    desc = repo['description']
+                    print ' ' * 5, 'Description: {0}'.format(desc)
 
+                if 'yum_repos' in repo:
+                    yum_repos = repo['yum_repos']
+                    print ' ' * 5, 'Yum repo: {0}'.format(yum_repos)
+
+                if 'additional_repos' in repo:
+                    add_repos = repo['additional_repos']
+                    print ' ' * 5, 'Additional repos: {0}'.format(add_repos)
+
+                if 'instructions' in repo:
+                    instructions = repo['instructions']
+                    print ' ' * 5, 'Instructions: {0}'.format(instructions)
+
+        else:
+            print 'No copr retrieved for user: "{0}"'.format(
+                user['username'])
     else:
-        headers = columns[0]
-        print headers
-        print "-"*len(headers)
-        print values[0]
+        print 'Un-expected data returned, please report this issue'
 
 
 def create(name, chroots=[], description=None, instructions=None,
-- 
1.8.3.1



More information about the copr-devel mailing list