aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gentoo.org>2020-01-02 09:50:31 -0800
committerMatt Turner <mattst88@gentoo.org>2020-01-02 13:24:54 -0800
commit059b8857c2114f2ca0cec3ec5408d28ecc38ee62 (patch)
treedfdf2252a5d027df7ff365bf266aa3e5ea690bb7
parenteclean: Fix typos (diff)
downloadgentoolkit-059b8857c2114f2ca0cec3ec5408d28ecc38ee62.tar.gz
gentoolkit-059b8857c2114f2ca0cec3ec5408d28ecc38ee62.tar.bz2
gentoolkit-059b8857c2114f2ca0cec3ec5408d28ecc38ee62.zip
imlate: Dynamically calculate column width in report
Also print categories on the line with the package name for much simpler consumption by external tools. Signed-off-by: Matt Turner <mattst88@gentoo.org>
-rwxr-xr-xpym/gentoolkit/imlate/imlate.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/pym/gentoolkit/imlate/imlate.py b/pym/gentoolkit/imlate/imlate.py
index 86d1a7e..40e2914 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:
+ for pkg in pkgs[cat]:
+ 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()