Gentoo Archives: gentoo-portage-dev

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