Skip to content

Commit

Permalink
portageq: Allow envvar to treat a trailing * as a wildcard
Browse files Browse the repository at this point in the history
This matches multiple variables, which is particularly useful in
multilib situations.

Signed-off-by: James Le Cuirot <chewi@gentoo.org>
  • Loading branch information
chewi committed Jan 24, 2025
1 parent 5f6a133 commit 99d8bde
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
7 changes: 7 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ Release notes take the form of the following optional categories:
* Bug fixes
* Cleanups

portage-3.0.68 (UNRELEASED)
--------------

Features:
* Allow "portageq envvar" to treat a trailing * as a wildcard, matching multiple
variables. Useful for multilib.

portage-3.0.67 (2025-01-22)
--------------

Expand Down
24 changes: 16 additions & 8 deletions bin/portageq
Original file line number Diff line number Diff line change
Expand Up @@ -877,22 +877,30 @@ try:
file=sys.stderr,
)

value = portage.settings.get(arg)
if value is None:
value = ""
exit_status = 1

if verbose:
print(arg + "=" + shlex.quote(value))
if arg.endswith("*"):
arg = arg[0:-1]
keys = [key for key in portage.settings.keys() if key.startswith(arg)]
else:
print(value)
keys = (arg,)

for key in keys:
value = portage.settings.get(key)
if value is None:
value = ""
exit_status = 1

if verbose:
print(key + "=" + shlex.quote(value))
else:
print(value)

return exit_status

docstrings[
"envvar"
] = """<variable>+
Returns a specific environment variable as exists prior to ebuild.sh.
Variable names can end with * to match multiple variables.
Similar to: emerge --verbose --info | grep -E '^<variable>='
"""
envvar.__doc__ = docstrings["envvar"]
Expand Down
1 change: 1 addition & 0 deletions lib/portage/tests/emerge/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ def _generate_all_baseline_commands(playground, binhost):
"EROOT",
"PORTAGE_CONFIGROOT",
"PORTAGE_TMPDIR",
"CHOST*",
"USERLAND",
)
test_commands["etc-update"] = EtcUpdate()
Expand Down

0 comments on commit 99d8bde

Please sign in to comment.