From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 6460315ACFB for ; Sat, 22 Apr 2023 16:56:40 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A0B31E0932; Sat, 22 Apr 2023 16:56:39 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0431EE0932 for ; Sat, 22 Apr 2023 16:56:38 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id E381F34017A for ; Sat, 22 Apr 2023 16:56:36 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 7D96FA40 for ; Sat, 22 Apr 2023 16:56:35 +0000 (UTC) From: "Arthur Zamarin" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Arthur Zamarin" Message-ID: <1682182417.1d12cafe86c5bb9806b043513b84292205131e83.arthurzam@gentoo> Subject: [gentoo-commits] proj/pkgcore/pkgdev:main commit in: src/pkgdev/scripts/ X-VCS-Repository: proj/pkgcore/pkgdev X-VCS-Files: src/pkgdev/scripts/pkgdev_bugs.py X-VCS-Directories: src/pkgdev/scripts/ X-VCS-Committer: arthurzam X-VCS-Committer-Name: Arthur Zamarin X-VCS-Revision: 1d12cafe86c5bb9806b043513b84292205131e83 X-VCS-Branch: main Date: Sat, 22 Apr 2023 16:56:35 +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-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 7a662953-6c82-4449-8f03-6a3b5149d21f X-Archives-Hash: f8a2c8565681ef89ff91bdeda44d7aa5 commit: 1d12cafe86c5bb9806b043513b84292205131e83 Author: Arthur Zamarin gentoo org> AuthorDate: Sat Apr 22 16:53:37 2023 +0000 Commit: Arthur Zamarin gentoo org> CommitDate: Sat Apr 22 16:53:37 2023 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=1d12cafe bugs: support piping package list from stdin When calling the tool without packages (for example just `pkgdev bugs`), and you pipe (from a file or another command) a list of packages, it will read the package list and use it. The input file can have empty lines, and comments. Everything after the first # is considered a comment. Whitespaces are stripped. Resolves: https://github.com/pkgcore/pkgdev/issues/136 Signed-off-by: Arthur Zamarin gentoo.org> src/pkgdev/scripts/pkgdev_bugs.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/pkgdev/scripts/pkgdev_bugs.py b/src/pkgdev/scripts/pkgdev_bugs.py index 4a7f34c..98d84f9 100644 --- a/src/pkgdev/scripts/pkgdev_bugs.py +++ b/src/pkgdev/scripts/pkgdev_bugs.py @@ -1,6 +1,7 @@ """Automatic bugs filer""" import json +import sys import urllib.request as urllib from collections import defaultdict from functools import partial @@ -19,7 +20,7 @@ from pkgcore.ebuild.misc import sort_keywords from pkgcore.repository import multiplex from pkgcore.restrictions import boolean, packages, values from pkgcore.test.misc import FakePkg -from pkgcore.util import commandline +from pkgcore.util import commandline, parserestrict from snakeoil.cli import arghparse from snakeoil.cli.input import userquery from snakeoil.formatters import Formatter @@ -47,7 +48,7 @@ bugs.add_argument( bugs.add_argument( "targets", metavar="target", - nargs="+", + nargs="*", action=commandline.StoreTarget, help="extended atom matching of packages", ) @@ -285,10 +286,8 @@ class DependencyGraph: match = self.find_best_match(deps, pkgset) except (ValueError, IndexError): deps_str = " , ".join(map(str, deps)) - self.err.write( - self.err.fg("red"), + self.err.error( f"unable to find match for restrictions: {deps_str}", - self.err.reset, ) raise results[match].add(keyword) @@ -461,6 +460,18 @@ class DependencyGraph: node.file_bug(api_key, auto_cc_arches, observe) +def _load_from_stdin(out: Formatter, err: Formatter): + if not sys.stdin.isatty(): + out.warn("No packages were specified, reading from stdin...") + for line in sys.stdin.readlines(): + if line := line.split("#", 1)[0].strip(): + yield line, parserestrict.parse_match(line) + # reassign stdin to allow interactivity (currently only works for unix) + sys.stdin = open("/dev/tty") + else: + raise arghparse.ArgumentError(None, "reading from stdin is only valid when piping data in") + + def _parse_targets(search_repo, targets): for _, target in targets: try: @@ -472,6 +483,7 @@ def _parse_targets(search_repo, targets): @bugs.bind_main_func def main(options, out: Formatter, err: Formatter): search_repo = options.search_repo + options.targets = options.targets or list(_load_from_stdin(out, err)) targets = list(_parse_targets(search_repo, options.targets)) d = DependencyGraph(out, err, options) d.build_full_graph(targets)