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