Also print categories on the line with the package name for much simpler
consumption by external tools.

Signed-off-by: Matt Turner <matts...@gentoo.org>
---
 pym/gentoolkit/imlate/imlate.py | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/pym/gentoolkit/imlate/imlate.py b/pym/gentoolkit/imlate/imlate.py
index 86d1a7e..a5568d7 100755
--- a/pym/gentoolkit/imlate/imlate.py
+++ b/pym/gentoolkit/imlate/imlate.py
@@ -67,11 +67,18 @@ def _fill( width, line, fill = " " ):
 # create a hopefully pretty result
 def show_result( conf, pkgs ):
        # X - len(colX) = space to fill
-       col1 = 40
-       col2 = 20
+       col1 = -1
+       col2 = -1
+       for cat in pkgs.keys():
+               for pkg in pkgs[cat].keys():
+                       col1 = max(col1, len(("%s/%s" % (cat, pkg))))
+                       col2 = max(col2, len(pkgs[cat][pkg][1]))
+       col1 += 1
+       col2 += 1
 
        _header = "%s candidates for 'gentoo' on '%s'"
-       _helper = "category/package[:SLOT]                 our version         
best version"
+       _helper = "%s%s%s" % (_fill(col1, "category/package[:SLOT])"),
+                                                 _fill(col2, "our version"), 
"best version")
        _cand = ""
        header = ""
 
@@ -102,11 +109,10 @@ def show_result( conf, pkgs ):
        print(_fill( len( _helper ), "", "-" ), file=out)
 
        for cat in sorted( pkgs.keys() ):
-               print("%s/" % cat, file=out)
                for pkg in sorted( pkgs[cat].keys() ):
-                       print("%s%s%s" % ( _fill( col1, ( "  %s" % pkg ) ),
-                                                                       _fill( 
col2, pkgs[cat][pkg][1] ),
-                                                                       
pkgs[cat][pkg][0] ), file=out)
+                       print("%s%s%s" % (_fill(col1, ("%s/%s" % (cat, pkg))),
+                                                         _fill(col2, 
pkgs[cat][pkg][1]),
+                                                         pkgs[cat][pkg][0] ), 
file=out)
 
        if conf["FILE"] != "stdout":
                out.close()
-- 
2.24.1


Reply via email to