Re: [gentoo-portage-dev] [PATCH] Add --output-style option to repoman
On Mon, Feb 10, 2014 at 2:57 PM, Chris Reffett wrote: > This patch adds a --output-style option to repoman, which gives the user > a choice of output formats for the repoman checks. Choices are "default" > (current style) and "column" (a greppable format), but it should be easy > to add more. Fixes bug 481584. > --- > bin/repoman | 18 +- > pym/repoman/utilities.py | 38 ++ > 2 files changed, 55 insertions(+), 1 deletion(-) > > diff --git a/bin/repoman b/bin/repoman > index 3504b6b..957ee08 100755 > --- a/bin/repoman > +++ b/bin/repoman > @@ -144,9 +144,17 @@ def ParseArgs(argv, qahelp): > 'scan' : 'Scan directory tree for QA issues' > } > > + output_choices = { > + 'default' : 'The normal output format', > + 'column' : 'Columnar output suitable for use with grep' > + } > + > mode_keys = list(modes) > mode_keys.sort() > > output_keys = sorted(output_choices) ? > + output_keys = list(output_choices) > + output_keys.sort > + > parser = ArgumentParser(usage="repoman [options] [mode]", > description="Modes: %s" % " | ".join(mode_keys), > epilog="For more help consult the man page.") > @@ -228,6 +236,9 @@ def ParseArgs(argv, qahelp): > parser.add_argument('--without-mask', dest='without_mask', > action='store_true', > default=False, help='behave as if no package.mask entries > exist (not allowed with commit mode)') > > + parser.add_argument('--output-style', dest='output_style', > choices=output_keys, > + help='select output type') > + > parser.add_argument('--mode', dest='mode', choices=mode_keys, > help='specify which mode repoman will run in > (default=full)') > > @@ -256,6 +267,8 @@ def ParseArgs(argv, qahelp): > if opts.mode == 'ci': > opts.mode = 'commit' # backwards compat shortcut > > + if not opts.output_style: > + opts.output_style = 'default' #default to the standard > output type > # Use the verbosity and quiet options to fiddle with the loglevel > appropriately > for val in range(opts.verbosity): > logger = logging.getLogger() > @@ -2422,7 +2435,10 @@ console_writer.style_listener = > style_file.new_styles > > f = formatter.AbstractFormatter(console_writer) > > -utilities.format_qa_output(f, stats, fails, dofull, dofail, options, > qawarnings) > +if options.output_style == 'column': > + utilities.format_qa_output_column(f, stats, fails, dofull, dofail, > options, qawarnings) > +else: > + utilities.format_qa_output(f, stats, fails, dofull, dofail, > options, qawarnings) > > style_file.flush() > del console_writer, f, style_file > diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py > index 3ec3a4a..713f208 100644 > --- a/pym/repoman/utilities.py > +++ b/pym/repoman/utilities.py > @@ -330,6 +330,44 @@ def format_qa_output(formatter, stats, fails, dofull, > dofail, options, qawarning > formatter.add_line_break() > > > +def format_qa_output_column(formatter, stats, fails, dofull, dofail, > options, qawarnings): > + """Helper function that formats output in a machine-parseable > column format > + > + Args: > + formatter - a subclass of Formatter > + stats - a dict of qa status items > + fails - a dict of qa status failures > + dofull - boolean to print full results or a summary > + dofail - boolean to decide if failure was hard or soft > missing options and qawarnings ? > + > + Returns: > + None (modifies formatter) > + """ > + full = options.mode == 'full' > + for category, number in stats.items(): > + # we only want key value pairs where value > 0 > + if number < 1: > + continue > + > + formatter.add_literal_data("NumberOf " + category + " ") > + if category in qawarnings: > + formatter.push_style("WARN") > + else: > + formatter.push_style("BAD") > + formatter.add_literal_data("%s" % number) > + formatter.pop_style() > + formatter.add_line_break() > + if not dofull: > + if not full and dofail and category in qawarnings: > + # warnings are considered noise when there > are failures > + continue > + fails_list = fails[category] > + if not full and len(fails_list) > 12: > + fails_list = fails_list[:12] > + for failure in fails_list: > + formatter.add_literal_data(category + " " > + failure) >
Re: [gentoo-portage-dev] [PATCH] Add --output-style option to repoman
On Mon, 10 Feb 2014 17:57:26 -0500 Chris Reffett wrote: > This patch adds a --output-style option to repoman, which gives the > user a choice of output formats for the repoman checks. Choices are > "default" (current style) and "column" (a greppable format), but it > should be easy to add more. Fixes bug 481584. > --- > bin/repoman | 18 +- > pym/repoman/utilities.py | 38 ++ > 2 files changed, 55 insertions(+), 1 deletion(-) > > diff --git a/bin/repoman b/bin/repoman > index 3504b6b..957ee08 100755 > --- a/bin/repoman > +++ b/bin/repoman > @@ -144,9 +144,17 @@ def ParseArgs(argv, qahelp): > 'scan' : 'Scan directory tree for QA issues' > } > > + output_choices = { > + 'default' : 'The normal output format', > + 'column' : 'Columnar output suitable for use with > grep' > + } > + > mode_keys = list(modes) > mode_keys.sort() > > + output_keys = list(output_choices) > + output_keys.sort > + > parser = ArgumentParser(usage="repoman [options] [mode]", > description="Modes: %s" % " | ".join(mode_keys), > epilog="For more help consult the man page.") > @@ -228,6 +236,9 @@ def ParseArgs(argv, qahelp): > parser.add_argument('--without-mask', dest='without_mask', > action='store_true', default=False, help='behave as if no > package.mask entries exist (not allowed with commit mode)') > + parser.add_argument('--output-style', dest='output_style', > choices=output_keys, > + help='select output type') Why not set the default right here? + parser.add_argument('--output-style', dest='output_style', choices=output_keys, default='default', + help='select output type') > + > parser.add_argument('--mode', dest='mode', choices=mode_keys, > help='specify which mode repoman will run in > (default=full)') > @@ -256,6 +267,8 @@ def ParseArgs(argv, qahelp): > if opts.mode == 'ci': > opts.mode = 'commit' # backwards compat shortcut > > + if not opts.output_style: > + opts.output_style = 'default' #default to the standard output type delete ^^^ not needed if you set the default as above ># Use the verbosity and quiet options to fiddle > with the loglevel appropriately for val in range(opts.verbosity): > logger = logging.getLogger() > @@ -2422,7 +2435,10 @@ console_writer.style_listener = > style_file.new_styles > f = formatter.AbstractFormatter(console_writer) > > -utilities.format_qa_output(f, stats, fails, dofull, dofail, options, > qawarnings) +if options.output_style == 'column': > + utilities.format_qa_output_column(f, stats, fails, dofull, > dofail, options, qawarnings) +else: > + utilities.format_qa_output(f, stats, fails, dofull, dofail, > options, qawarnings) > style_file.flush() > del console_writer, f, style_file > diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py > index 3ec3a4a..713f208 100644 > --- a/pym/repoman/utilities.py > +++ b/pym/repoman/utilities.py > @@ -330,6 +330,44 @@ def format_qa_output(formatter, stats, fails, > dofull, dofail, options, qawarning formatter.add_line_break() > > > +def format_qa_output_column(formatter, stats, fails, dofull, dofail, > options, qawarnings): > + """Helper function that formats output in a > machine-parseable column format + > + Args: > + formatter - a subclass of Formatter > + stats - a dict of qa status items > + fails - a dict of qa status failures > + dofull - boolean to print full results or a summary > + dofail - boolean to decide if failure was hard or > soft + > + Returns: > + None (modifies formatter) > + """ I thought we had a doc around that stated the format for docstrings. I recall it being a different format that the above parameter descriptions. > + full = options.mode == 'full' > + for category, number in stats.items(): > + # we only want key value pairs where value > 0 > + if number < 1: > + continue > + > + formatter.add_literal_data("NumberOf " + category + > " ") > + if category in qawarnings: > + formatter.push_style("WARN") > + else: > + formatter.push_style("BAD") > + formatter.add_literal_data("%s" % number) > + formatter.pop_style() > + formatter.add_line_break() > + if not dofull: > + if not full and dofail and category in > qawarnings: > + # warnings are considered noise when > there are failures > + continue > + fails_list = fails[category] > + if not full and len(fails_list) > 12: > + fails_list = fails_list[:12
[gentoo-portage-dev] [PATCH] Add --output-style option to repoman
This patch adds a --output-style option to repoman, which gives the user a choice of output formats for the repoman checks. Choices are "default" (current style) and "column" (a greppable format), but it should be easy to add more. Fixes bug 481584. --- bin/repoman | 18 +- pym/repoman/utilities.py | 38 ++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/bin/repoman b/bin/repoman index 3504b6b..957ee08 100755 --- a/bin/repoman +++ b/bin/repoman @@ -144,9 +144,17 @@ def ParseArgs(argv, qahelp): 'scan' : 'Scan directory tree for QA issues' } + output_choices = { + 'default' : 'The normal output format', + 'column' : 'Columnar output suitable for use with grep' + } + mode_keys = list(modes) mode_keys.sort() + output_keys = list(output_choices) + output_keys.sort + parser = ArgumentParser(usage="repoman [options] [mode]", description="Modes: %s" % " | ".join(mode_keys), epilog="For more help consult the man page.") @@ -228,6 +236,9 @@ def ParseArgs(argv, qahelp): parser.add_argument('--without-mask', dest='without_mask', action='store_true', default=False, help='behave as if no package.mask entries exist (not allowed with commit mode)') + parser.add_argument('--output-style', dest='output_style', choices=output_keys, + help='select output type') + parser.add_argument('--mode', dest='mode', choices=mode_keys, help='specify which mode repoman will run in (default=full)') @@ -256,6 +267,8 @@ def ParseArgs(argv, qahelp): if opts.mode == 'ci': opts.mode = 'commit' # backwards compat shortcut + if not opts.output_style: + opts.output_style = 'default' #default to the standard output type # Use the verbosity and quiet options to fiddle with the loglevel appropriately for val in range(opts.verbosity): logger = logging.getLogger() @@ -2422,7 +2435,10 @@ console_writer.style_listener = style_file.new_styles f = formatter.AbstractFormatter(console_writer) -utilities.format_qa_output(f, stats, fails, dofull, dofail, options, qawarnings) +if options.output_style == 'column': + utilities.format_qa_output_column(f, stats, fails, dofull, dofail, options, qawarnings) +else: + utilities.format_qa_output(f, stats, fails, dofull, dofail, options, qawarnings) style_file.flush() del console_writer, f, style_file diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index 3ec3a4a..713f208 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -330,6 +330,44 @@ def format_qa_output(formatter, stats, fails, dofull, dofail, options, qawarning formatter.add_line_break() +def format_qa_output_column(formatter, stats, fails, dofull, dofail, options, qawarnings): + """Helper function that formats output in a machine-parseable column format + + Args: + formatter - a subclass of Formatter + stats - a dict of qa status items + fails - a dict of qa status failures + dofull - boolean to print full results or a summary + dofail - boolean to decide if failure was hard or soft + + Returns: + None (modifies formatter) + """ + full = options.mode == 'full' + for category, number in stats.items(): + # we only want key value pairs where value > 0 + if number < 1: + continue + + formatter.add_literal_data("NumberOf " + category + " ") + if category in qawarnings: + formatter.push_style("WARN") + else: + formatter.push_style("BAD") + formatter.add_literal_data("%s" % number) + formatter.pop_style() + formatter.add_line_break() + if not dofull: + if not full and dofail and category in qawarnings: + # warnings are considered noise when there are failures + continue + fails_list = fails[category] + if not full and len(fails_list) > 12: + fails_list = fails_list[:12] + for failure in fails_list: + formatter.add_literal_data(category + " " + failure) + formatter.add_line_break() + def editor_is_executable(editor): """ Given an EDITOR string, validate that it refers to -- 1.8.5.3