commit: 059b8857c2114f2ca0cec3ec5408d28ecc38ee62
Author: Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Jan 2 17:50:31 2020 +0000
Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Jan 2 21:24:54 2020 +0000
URL: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=059b8857
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 <AT> 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..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()