Gentoo Archives: gentoo-commits

From: Matt Turner <mattst88@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/imlate/
Date: Fri, 03 Jan 2020 04:31:28
Message-Id: 1578000294.059b8857c2114f2ca0cec3ec5408d28ecc38ee62.mattst88@gentoo
1 commit: 059b8857c2114f2ca0cec3ec5408d28ecc38ee62
2 Author: Matt Turner <mattst88 <AT> gentoo <DOT> org>
3 AuthorDate: Thu Jan 2 17:50:31 2020 +0000
4 Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org>
5 CommitDate: Thu Jan 2 21:24:54 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=059b8857
7
8 imlate: Dynamically calculate column width in report
9
10 Also print categories on the line with the package name for much simpler
11 consumption by external tools.
12
13 Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>
14
15 pym/gentoolkit/imlate/imlate.py | 20 +++++++++++++-------
16 1 file changed, 13 insertions(+), 7 deletions(-)
17
18 diff --git a/pym/gentoolkit/imlate/imlate.py b/pym/gentoolkit/imlate/imlate.py
19 index 86d1a7e..40e2914 100755
20 --- a/pym/gentoolkit/imlate/imlate.py
21 +++ b/pym/gentoolkit/imlate/imlate.py
22 @@ -67,11 +67,18 @@ def _fill( width, line, fill = " " ):
23 # create a hopefully pretty result
24 def show_result( conf, pkgs ):
25 # X - len(colX) = space to fill
26 - col1 = 40
27 - col2 = 20
28 + col1 = -1
29 + col2 = -1
30 + for cat in pkgs:
31 + for pkg in pkgs[cat]:
32 + col1 = max(col1, len(("%s/%s" % (cat, pkg))))
33 + col2 = max(col2, len(pkgs[cat][pkg][1]))
34 + col1 += 1
35 + col2 += 1
36
37 _header = "%s candidates for 'gentoo' on '%s'"
38 - _helper = "category/package[:SLOT] our version best version"
39 + _helper = "%s%s%s" % (_fill(col1, "category/package[:SLOT])"),
40 + _fill(col2, "our version"), "best version")
41 _cand = ""
42 header = ""
43
44 @@ -102,11 +109,10 @@ def show_result( conf, pkgs ):
45 print(_fill( len( _helper ), "", "-" ), file=out)
46
47 for cat in sorted( pkgs.keys() ):
48 - print("%s/" % cat, file=out)
49 for pkg in sorted( pkgs[cat].keys() ):
50 - print("%s%s%s" % ( _fill( col1, ( " %s" % pkg ) ),
51 - _fill( col2, pkgs[cat][pkg][1] ),
52 - pkgs[cat][pkg][0] ), file=out)
53 + print("%s%s%s" % (_fill(col1, ("%s/%s" % (cat, pkg))),
54 + _fill(col2, pkgs[cat][pkg][1]),
55 + pkgs[cat][pkg][0] ), file=out)
56
57 if conf["FILE"] != "stdout":
58 out.close()