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 |
bin/repoman | 18 +++++++++++++++++- |
7 |
pym/repoman/utilities.py | 38 ++++++++++++++++++++++++++++++++++++++ |
8 |
2 files changed, 55 insertions(+), 1 deletion(-) |
9 |
|
10 |
diff --git a/bin/repoman b/bin/repoman |
11 |
index 3504b6b..957ee08 100755 |
12 |
--- a/bin/repoman |
13 |
+++ b/bin/repoman |
14 |
@@ -144,9 +144,17 @@ def ParseArgs(argv, qahelp): |
15 |
'scan' : 'Scan directory tree for QA issues' |
16 |
} |
17 |
|
18 |
+ output_choices = { |
19 |
+ 'default' : 'The normal output format', |
20 |
+ 'column' : 'Columnar output suitable for use with grep' |
21 |
+ } |
22 |
+ |
23 |
mode_keys = list(modes) |
24 |
mode_keys.sort() |
25 |
|
26 |
+ output_keys = list(output_choices) |
27 |
+ output_keys.sort |
28 |
+ |
29 |
parser = ArgumentParser(usage="repoman [options] [mode]", |
30 |
description="Modes: %s" % " | ".join(mode_keys), |
31 |
epilog="For more help consult the man page.") |
32 |
@@ -228,6 +236,9 @@ def ParseArgs(argv, qahelp): |
33 |
parser.add_argument('--without-mask', dest='without_mask', action='store_true', |
34 |
default=False, help='behave as if no package.mask entries exist (not allowed with commit mode)') |
35 |
|
36 |
+ parser.add_argument('--output-style', dest='output_style', choices=output_keys, |
37 |
+ help='select output type') |
38 |
+ |
39 |
parser.add_argument('--mode', dest='mode', choices=mode_keys, |
40 |
help='specify which mode repoman will run in (default=full)') |
41 |
|
42 |
@@ -256,6 +267,8 @@ def ParseArgs(argv, qahelp): |
43 |
if opts.mode == 'ci': |
44 |
opts.mode = 'commit' # backwards compat shortcut |
45 |
|
46 |
+ if not opts.output_style: |
47 |
+ opts.output_style = 'default' #default to the standard output type |
48 |
# Use the verbosity and quiet options to fiddle with the loglevel appropriately |
49 |
for val in range(opts.verbosity): |
50 |
logger = logging.getLogger() |
51 |
@@ -2422,7 +2435,10 @@ console_writer.style_listener = style_file.new_styles |
52 |
|
53 |
f = formatter.AbstractFormatter(console_writer) |
54 |
|
55 |
-utilities.format_qa_output(f, stats, fails, dofull, dofail, options, qawarnings) |
56 |
+if options.output_style == 'column': |
57 |
+ utilities.format_qa_output_column(f, stats, fails, dofull, dofail, options, qawarnings) |
58 |
+else: |
59 |
+ utilities.format_qa_output(f, stats, fails, dofull, dofail, options, qawarnings) |
60 |
|
61 |
style_file.flush() |
62 |
del console_writer, f, style_file |
63 |
diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py |
64 |
index 3ec3a4a..713f208 100644 |
65 |
--- a/pym/repoman/utilities.py |
66 |
+++ b/pym/repoman/utilities.py |
67 |
@@ -330,6 +330,44 @@ def format_qa_output(formatter, stats, fails, dofull, dofail, options, qawarning |
68 |
formatter.add_line_break() |
69 |
|
70 |
|
71 |
+def format_qa_output_column(formatter, stats, fails, dofull, dofail, options, qawarnings): |
72 |
+ """Helper function that formats output in a machine-parseable column format |
73 |
+ |
74 |
+ Args: |
75 |
+ formatter - a subclass of Formatter |
76 |
+ stats - a dict of qa status items |
77 |
+ fails - a dict of qa status failures |
78 |
+ dofull - boolean to print full results or a summary |
79 |
+ dofail - boolean to decide if failure was hard or soft |
80 |
+ |
81 |
+ Returns: |
82 |
+ None (modifies formatter) |
83 |
+ """ |
84 |
+ full = options.mode == 'full' |
85 |
+ for category, number in stats.items(): |
86 |
+ # we only want key value pairs where value > 0 |
87 |
+ if number < 1: |
88 |
+ continue |
89 |
+ |
90 |
+ formatter.add_literal_data("NumberOf " + category + " ") |
91 |
+ if category in qawarnings: |
92 |
+ formatter.push_style("WARN") |
93 |
+ else: |
94 |
+ formatter.push_style("BAD") |
95 |
+ formatter.add_literal_data("%s" % number) |
96 |
+ formatter.pop_style() |
97 |
+ formatter.add_line_break() |
98 |
+ if not dofull: |
99 |
+ if not full and dofail and category in qawarnings: |
100 |
+ # warnings are considered noise when there are failures |
101 |
+ continue |
102 |
+ fails_list = fails[category] |
103 |
+ if not full and len(fails_list) > 12: |
104 |
+ fails_list = fails_list[:12] |
105 |
+ for failure in fails_list: |
106 |
+ formatter.add_literal_data(category + " " + failure) |
107 |
+ formatter.add_line_break() |
108 |
+ |
109 |
def editor_is_executable(editor): |
110 |
""" |
111 |
Given an EDITOR string, validate that it refers to |
112 |
-- |
113 |
1.8.5.3 |