Gentoo Archives: gentoo-portage-dev

From: Chris Reffett <creffett@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH v2] Add --output-style option to repoman
Date: Tue, 11 Feb 2014 01:22:48
Message-Id: 1392081756-21088-1-git-send-email-creffett@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] Add --output-style option to repoman by Chris Reffett
1 This patch adds a --output-style option to repoman, which gives the user
2 a choice of output formats for the repoman checks. Choices are "default"
3 (current style) and "column" (a greppable format), but it should be easy
4 to add more. Fixes bug 481584.
5
6 v2: Fix docstring to be complete and in the standard format, make use of
7 default choices in --output-style wrt comments by antarus and dol-sen
8 ---
9 bin/repoman | 15 ++++++++++++++-
10 pym/repoman/utilities.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
11 2 files changed, 58 insertions(+), 1 deletion(-)
12
13 diff --git a/bin/repoman b/bin/repoman
14 index 3504b6b..c7a1c4c 100755
15 --- a/bin/repoman
16 +++ b/bin/repoman
17 @@ -144,9 +144,16 @@ def ParseArgs(argv, qahelp):
18 'scan' : 'Scan directory tree for QA issues'
19 }
20
21 + output_choices = {
22 + 'default' : 'The normal output format',
23 + 'column' : 'Columnar output suitable for use with grep'
24 + }
25 +
26 mode_keys = list(modes)
27 mode_keys.sort()
28
29 + output_keys = sorted(output_choices)
30 +
31 parser = ArgumentParser(usage="repoman [options] [mode]",
32 description="Modes: %s" % " | ".join(mode_keys),
33 epilog="For more help consult the man page.")
34 @@ -228,6 +235,9 @@ def ParseArgs(argv, qahelp):
35 parser.add_argument('--without-mask', dest='without_mask', action='store_true',
36 default=False, help='behave as if no package.mask entries exist (not allowed with commit mode)')
37
38 + parser.add_argument('--output-style', dest='output_style', choices=output_keys,
39 + help='select output type', default='default')
40 +
41 parser.add_argument('--mode', dest='mode', choices=mode_keys,
42 help='specify which mode repoman will run in (default=full)')
43
44 @@ -2422,7 +2432,10 @@ console_writer.style_listener = style_file.new_styles
45
46 f = formatter.AbstractFormatter(console_writer)
47
48 -utilities.format_qa_output(f, stats, fails, dofull, dofail, options, qawarnings)
49 +if options.output_style == 'column':
50 + utilities.format_qa_output_column(f, stats, fails, dofull, dofail, options, qawarnings)
51 +else:
52 + utilities.format_qa_output(f, stats, fails, dofull, dofail, options, qawarnings)
53
54 style_file.flush()
55 del console_writer, f, style_file
56 diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py
57 index 3ec3a4a..aec61fe 100644
58 --- a/pym/repoman/utilities.py
59 +++ b/pym/repoman/utilities.py
60 @@ -330,6 +330,50 @@ def format_qa_output(formatter, stats, fails, dofull, dofail, options, qawarning
61 formatter.add_line_break()
62
63
64 +def format_qa_output_column(formatter, stats, fails, dofull, dofail, options, qawarnings):
65 + """Helper function that formats output in a machine-parseable column format
66 +
67 + @param formatter: an instance of Formatter
68 + @type formatter: Formatter
69 + @param path: dict of qa status items
70 + @type path: dict
71 + @param fails: dict of qa status failures
72 + @type fails: dict
73 + @param dofull: Whether to print full results or a summary
74 + @type dofull: boolean
75 + @param dofail: Whether failure was hard or soft
76 + @type dofail: boolean
77 + @param options: The command-line options provided to repoman
78 + @type options: Namespace
79 + @param qawarnings: the set of warning types
80 + @type qawarnings: set
81 + @return: None (modifies formatter)
82 + """
83 + full = options.mode == 'full'
84 + for category, number in stats.items():
85 + # we only want key value pairs where value > 0
86 + if number < 1:
87 + continue
88 +
89 + formatter.add_literal_data("NumberOf " + category + " ")
90 + if category in qawarnings:
91 + formatter.push_style("WARN")
92 + else:
93 + formatter.push_style("BAD")
94 + formatter.add_literal_data("%s" % number)
95 + formatter.pop_style()
96 + formatter.add_line_break()
97 + if not dofull:
98 + if not full and dofail and category in qawarnings:
99 + # warnings are considered noise when there are failures
100 + continue
101 + fails_list = fails[category]
102 + if not full and len(fails_list) > 12:
103 + fails_list = fails_list[:12]
104 + for failure in fails_list:
105 + formatter.add_literal_data(category + " " + failure)
106 + formatter.add_line_break()
107 +
108 def editor_is_executable(editor):
109 """
110 Given an EDITOR string, validate that it refers to
111 --
112 1.8.5.3

Replies