Gentoo Archives: gentoo-portage-dev

From: Matt Turner <mattst88@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Matt Turner <mattst88@g.o>
Subject: [gentoo-portage-dev] [PATCH gentoolkit 2/2] imlate: Dynamically calculate column width in report
Date: Thu, 02 Jan 2020 18:58:11
Message-Id: 20200102185800.538954-2-mattst88@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH gentoolkit 1/2] eclean: Fix typos by Matt Turner
1 Also print categories on the line with the package name for much simpler
2 consumption by external tools.
3
4 Signed-off-by: Matt Turner <mattst88@g.o>
5 ---
6 pym/gentoolkit/imlate/imlate.py | 20 +++++++++++++-------
7 1 file changed, 13 insertions(+), 7 deletions(-)
8
9 diff --git a/pym/gentoolkit/imlate/imlate.py b/pym/gentoolkit/imlate/imlate.py
10 index 86d1a7e..a5568d7 100755
11 --- a/pym/gentoolkit/imlate/imlate.py
12 +++ b/pym/gentoolkit/imlate/imlate.py
13 @@ -67,11 +67,18 @@ def _fill( width, line, fill = " " ):
14 # create a hopefully pretty result
15 def show_result( conf, pkgs ):
16 # X - len(colX) = space to fill
17 - col1 = 40
18 - col2 = 20
19 + col1 = -1
20 + col2 = -1
21 + for cat in pkgs.keys():
22 + for pkg in pkgs[cat].keys():
23 + col1 = max(col1, len(("%s/%s" % (cat, pkg))))
24 + col2 = max(col2, len(pkgs[cat][pkg][1]))
25 + col1 += 1
26 + col2 += 1
27
28 _header = "%s candidates for 'gentoo' on '%s'"
29 - _helper = "category/package[:SLOT] our version best version"
30 + _helper = "%s%s%s" % (_fill(col1, "category/package[:SLOT])"),
31 + _fill(col2, "our version"), "best version")
32 _cand = ""
33 header = ""
34
35 @@ -102,11 +109,10 @@ def show_result( conf, pkgs ):
36 print(_fill( len( _helper ), "", "-" ), file=out)
37
38 for cat in sorted( pkgs.keys() ):
39 - print("%s/" % cat, file=out)
40 for pkg in sorted( pkgs[cat].keys() ):
41 - print("%s%s%s" % ( _fill( col1, ( " %s" % pkg ) ),
42 - _fill( col2, pkgs[cat][pkg][1] ),
43 - pkgs[cat][pkg][0] ), file=out)
44 + print("%s%s%s" % (_fill(col1, ("%s/%s" % (cat, pkg))),
45 + _fill(col2, pkgs[cat][pkg][1]),
46 + pkgs[cat][pkg][0] ), file=out)
47
48 if conf["FILE"] != "stdout":
49 out.close()
50 --
51 2.24.1

Replies