Gentoo Archives: gentoo-portage-dev

From: Brian Dolbec <dolsen@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] Add --output-style option to repoman
Date: Tue, 11 Feb 2014 00:20:47
Message-Id: 20140210161623.1a6ae461@big_daddy.dol-sen.ca
In Reply to: [gentoo-portage-dev] [PATCH] Add --output-style option to repoman by Chris Reffett
1 On Mon, 10 Feb 2014 17:57:26 -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 > bin/repoman | 18 +++++++++++++++++-
10 > pym/repoman/utilities.py | 38 ++++++++++++++++++++++++++++++++++++++
11 > 2 files changed, 55 insertions(+), 1 deletion(-)
12 >
13 > diff --git a/bin/repoman b/bin/repoman
14 > index 3504b6b..957ee08 100755
15 > --- a/bin/repoman
16 > +++ b/bin/repoman
17 > @@ -144,9 +144,17 @@ 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
24 > grep'
25 > + }
26 > +
27 > mode_keys = list(modes)
28 > mode_keys.sort()
29 >
30 > + output_keys = list(output_choices)
31 > + output_keys.sort
32 > +
33 > parser = ArgumentParser(usage="repoman [options] [mode]",
34 > description="Modes: %s" % " | ".join(mode_keys),
35 > epilog="For more help consult the man page.")
36 > @@ -228,6 +236,9 @@ def ParseArgs(argv, qahelp):
37 > parser.add_argument('--without-mask', dest='without_mask',
38 > action='store_true', default=False, help='behave as if no
39 > package.mask entries exist (not allowed with commit mode)')
40 > + parser.add_argument('--output-style', dest='output_style',
41 > choices=output_keys,
42 > + help='select output type')
43
44
45 Why not set the default right here?
46
47 + parser.add_argument('--output-style', dest='output_style',
48 choices=output_keys, default='default',
49 + help='select output type')
50
51 > +
52 > parser.add_argument('--mode', dest='mode', choices=mode_keys,
53 > help='specify which mode repoman will run in
54 > (default=full)')
55 > @@ -256,6 +267,8 @@ def ParseArgs(argv, qahelp):
56 > if opts.mode == 'ci':
57 > opts.mode = 'commit' # backwards compat shortcut
58 >
59 > + if not opts.output_style:
60 > + opts.output_style = 'default' #default to the
61 standard output type
62
63 delete ^^^ not needed if you set the default as above
64
65 ># Use the verbosity and quiet options to fiddle
66 > with the loglevel appropriately for val in range(opts.verbosity):
67 > logger = logging.getLogger()
68 > @@ -2422,7 +2435,10 @@ console_writer.style_listener =
69 > style_file.new_styles
70 > f = formatter.AbstractFormatter(console_writer)
71 >
72 > -utilities.format_qa_output(f, stats, fails, dofull, dofail, options,
73 > qawarnings) +if options.output_style == 'column':
74 > + utilities.format_qa_output_column(f, stats, fails, dofull,
75 > dofail, options, qawarnings) +else:
76 > + utilities.format_qa_output(f, stats, fails, dofull, dofail,
77 > options, qawarnings)
78 > style_file.flush()
79 > del console_writer, f, style_file
80 > diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py
81 > index 3ec3a4a..713f208 100644
82 > --- a/pym/repoman/utilities.py
83 > +++ b/pym/repoman/utilities.py
84 > @@ -330,6 +330,44 @@ def format_qa_output(formatter, stats, fails,
85 > dofull, dofail, options, qawarning formatter.add_line_break()
86 >
87 >
88 > +def format_qa_output_column(formatter, stats, fails, dofull, dofail,
89 > options, qawarnings):
90 > + """Helper function that formats output in a
91 > machine-parseable column format +
92 > + Args:
93 > + formatter - a subclass of Formatter
94 > + stats - a dict of qa status items
95 > + fails - a dict of qa status failures
96 > + dofull - boolean to print full results or a summary
97 > + dofail - boolean to decide if failure was hard or
98 > soft +
99 > + Returns:
100 > + None (modifies formatter)
101 > + """
102
103
104 I thought we had a doc around that stated the format for docstrings.
105 I recall it being a different format that the above parameter descriptions.
106
107
108
109 > + full = options.mode == 'full'
110 > + for category, number in stats.items():
111 > + # we only want key value pairs where value > 0
112 > + if number < 1:
113 > + continue
114 > +
115 > + formatter.add_literal_data("NumberOf " + category +
116 > " ")
117 > + if category in qawarnings:
118 > + formatter.push_style("WARN")
119 > + else:
120 > + formatter.push_style("BAD")
121 > + formatter.add_literal_data("%s" % number)
122 > + formatter.pop_style()
123 > + formatter.add_line_break()
124 > + if not dofull:
125 > + if not full and dofail and category in
126 > qawarnings:
127 > + # warnings are considered noise when
128 > there are failures
129 > + continue
130 > + fails_list = fails[category]
131 > + if not full and len(fails_list) > 12:
132 > + fails_list = fails_list[:12]
133 > + for failure in fails_list:
134 > + formatter.add_literal_data(category
135 > + " " + failure)
136 > + formatter.add_line_break()
137 > +
138 > def editor_is_executable(editor):
139 > """
140 > Given an EDITOR string, validate that it refers to
141
142
143
144 --
145 Brian Dolbec <dolsen>