From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id A988F138CEF for ; Wed, 12 Feb 2014 00:53:58 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 45224E08FC; Wed, 12 Feb 2014 00:53:58 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id C82A7E08FC for ; Wed, 12 Feb 2014 00:53:57 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D331C33F9ED for ; Wed, 12 Feb 2014 00:53:56 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 6449F18874 for ; Wed, 12 Feb 2014 00:53:54 +0000 (UTC) From: "Chris Reffett" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Chris Reffett" Message-ID: <1392166391.af0eca982f04409439e6310e602b55bed6cc623c.creffett@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/repoman/, bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/repoman pym/repoman/utilities.py X-VCS-Directories: pym/repoman/ bin/ X-VCS-Committer: creffett X-VCS-Committer-Name: Chris Reffett X-VCS-Revision: af0eca982f04409439e6310e602b55bed6cc623c X-VCS-Branch: master Date: Wed, 12 Feb 2014 00:53:54 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 42d9db60-6285-4481-b7c6-7defd4385489 X-Archives-Hash: fec4ea8b8c3144e9e3057df5595c6477 commit: af0eca982f04409439e6310e602b55bed6cc623c Author: Chris Reffett gentoo org> AuthorDate: Mon Feb 10 20:16:33 2014 +0000 Commit: Chris Reffett gentoo org> CommitDate: Wed Feb 12 00:53:11 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=af0eca98 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. v2: Fix docstring to be complete and in the standard format, make use of default choices in --output-style wrt comments by antarus and dol-sen --- bin/repoman | 15 ++++++++++++++- pym/repoman/utilities.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/bin/repoman b/bin/repoman index 3504b6b..c7a1c4c 100755 --- a/bin/repoman +++ b/bin/repoman @@ -144,9 +144,16 @@ 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) + parser = ArgumentParser(usage="repoman [options] [mode]", description="Modes: %s" % " | ".join(mode_keys), epilog="For more help consult the man page.") @@ -228,6 +235,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', default='default') + parser.add_argument('--mode', dest='mode', choices=mode_keys, help='specify which mode repoman will run in (default=full)') @@ -2422,7 +2432,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..aec61fe 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -330,6 +330,50 @@ 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 + + @param formatter: an instance of Formatter + @type formatter: Formatter + @param path: dict of qa status items + @type path: dict + @param fails: dict of qa status failures + @type fails: dict + @param dofull: Whether to print full results or a summary + @type dofull: boolean + @param dofail: Whether failure was hard or soft + @type dofail: boolean + @param options: The command-line options provided to repoman + @type options: Namespace + @param qawarnings: the set of warning types + @type qawarnings: set + @return: 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