commit: c4598e95a81b98bba9373b5f91ff53bcac304efa Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> AuthorDate: Wed Jan 15 19:59:58 2025 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> CommitDate: Wed Jan 15 19:59:58 2025 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=c4598e95
patom: support input from stdin when "-" is passed as an argument Resolves: https://github.com/pkgcore/pkgcore/issues/226 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> src/pkgcore/scripts/patom.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pkgcore/scripts/patom.py b/src/pkgcore/scripts/patom.py index ac7a2ef2..113bd853 100644 --- a/src/pkgcore/scripts/patom.py +++ b/src/pkgcore/scripts/patom.py @@ -1,6 +1,7 @@ """atom parsing utility""" import re +import sys from functools import partial from ..ebuild.atom import atom as atom_cls @@ -90,6 +91,14 @@ def _transform_format(atom: atom_cls, match: re.Match): def main(options, out, err): if options.format: fmt, *atoms = options.format + + if "-" in atoms: + atoms = [atom for atom in atoms if atom != "-"] + if not sys.stdin.isatty(): + atoms += [x.strip() for x in sys.stdin.readlines()] + else: + argparser.error("reading from stdin is only valid when piping data in") + VAR_REGEX = re.compile(r"%\[.+?\]|%\{.+?\}") for value in atoms: try:
