public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Arthur Zamarin" <arthurzam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/pkgcore/pkgdev:main commit in: src/pkgdev/scripts/
Date: Sat, 22 Apr 2023 16:56:35 +0000 (UTC)	[thread overview]
Message-ID: <1682182417.1d12cafe86c5bb9806b043513b84292205131e83.arthurzam@gentoo> (raw)

commit:     1d12cafe86c5bb9806b043513b84292205131e83
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Sat Apr 22 16:53:37 2023 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> 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 <arthurzam <AT> 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)


             reply	other threads:[~2023-04-22 16:56 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-22 16:56 Arthur Zamarin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-07-20 15:37 [gentoo-commits] proj/pkgcore/pkgdev:main commit in: src/pkgdev/scripts/ Arthur Zamarin
2024-06-12 10:35 Arthur Zamarin
2024-05-31 11:13 Arthur Zamarin
2024-03-12 19:49 Arthur Zamarin
2024-03-12 19:38 Arthur Zamarin
2024-02-26 20:48 Arthur Zamarin
2024-01-25 16:01 Arthur Zamarin
2024-01-23 20:47 Arthur Zamarin
2023-12-30 13:37 Arthur Zamarin
2023-12-30 13:08 Arthur Zamarin
2023-12-30 10:45 Arthur Zamarin
2023-12-22 13:28 Arthur Zamarin
2023-12-17  5:44 Arthur Zamarin
2023-12-15 19:52 Arthur Zamarin
2023-12-15 11:42 Arthur Zamarin
2023-12-15 10:44 Arthur Zamarin
2023-09-08 12:13 Arthur Zamarin
2023-09-08 12:13 Arthur Zamarin
2023-09-08 12:13 Arthur Zamarin
2023-06-22 16:16 Arthur Zamarin
2023-06-09 16:52 Arthur Zamarin
2023-06-09 14:21 Arthur Zamarin
2023-05-28 19:41 Arthur Zamarin
2023-05-05 17:49 Arthur Zamarin
2023-04-22 16:32 Arthur Zamarin
2023-04-22 16:16 Arthur Zamarin
2023-04-20 18:37 Arthur Zamarin
2023-03-27 18:38 Arthur Zamarin
2023-03-18 18:20 Arthur Zamarin
2023-03-11 16:07 Arthur Zamarin
2023-03-05 19:55 Arthur Zamarin
2023-03-04 15:05 Arthur Zamarin
2023-01-13 21:39 Arthur Zamarin
2023-01-13 21:07 Arthur Zamarin
2022-11-19 12:51 Arthur Zamarin
2022-10-04  8:03 Arthur Zamarin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1682182417.1d12cafe86c5bb9806b043513b84292205131e83.arthurzam@gentoo \
    --to=arthurzam@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox