Skip to content

Commit

Permalink
Merge pull request #497 from citrus-it/pkg.fmri
Browse files Browse the repository at this point in the history
Add synthetic pkg.fmri.name attribute to pkgmogrify
  • Loading branch information
oetiker authored Oct 2, 2024
2 parents f58bac4 + e8d4fcc commit 4c0b4e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
13 changes: 11 additions & 2 deletions src/man/pkgmogrify.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
.\" Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
.Dd February 17, 2022
.\" Copyright 2024 OmniOS Community Edition (OmniOSce) Association.
.Dd October 1, 2024
.Dt PKGMOGRIFY 1
.Os
.Sh NAME
Expand Down Expand Up @@ -309,6 +309,15 @@ action, or it is treated as
described above.
When the processing reaches the end of the manifest file describing the
package, the attributes are cleared for the next package.
The following synthetic attributes are also automatically generated from
.Sy pkg.fmri
when it is encountered:
.Bl -tag -width Ds
.It Cm pkg.fmri.name
The name of the package, without any scheme, publisher name or version
information, e.g.
.Sq library/libxml2 .
.El
.Pp
It is useful not only to reference package attributes as if they were action
attributes, but also to match on them, and even temporarily modify them.
Expand Down
5 changes: 5 additions & 0 deletions src/modules/mogrify.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,11 @@ def process_mog(
pkg_attrs.setdefault(name, []).append(value)
else:
pkg_attrs.setdefault(name, []).extend(value)
if name == "pkg.fmri":
pfmri = pkg.fmri.PkgFmri(value)
pkg_attrs.setdefault("pkg.fmri.name", []).append(
pfmri.get_name()
)
comment, a = apply_transforms(
transforms, act, pkg_attrs, verbose, filename, lineno
)
Expand Down
12 changes: 8 additions & 4 deletions src/tests/cli/t_pkgmogrify.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class TestPkgMogrify(pkg5unittest.CliTestCase):
"""

pkgcontents2 = """\
set name=pkg.fmri value=wombat/[email protected],5.11-0.101
set name=pkg.fmri value=pkg://tp/wombat/[email protected],5.11-0.101
set name=bugs value=12345 value=54321 value=13524
set name=justonebug value=12345
file thisismyhashvalue path=usr/bin/foo mode=0777 owner=root group=bin
Expand Down Expand Up @@ -111,6 +111,7 @@ class TestPkgMogrify(pkg5unittest.CliTestCase):
"exit7 on bobcat": "<transform file bobcat=1 -> exit 7>",
"exit6 on bobcat": "<transform file bobcat=1 -> exit 6 found a bobcat>",
"pkg.fmri": '<transform file path=usr/bin/foo -> print pkg attr "%{{pkg.fmri}}" and the rest>',
"pkg.fmri.name": '<transform file path=usr/bin/foo -> print pkg attr "%{{pkg.fmri.name}}" and the rest>',
"pkg.bugs": '<transform file path=usr/bin/foo -> print pkg attr "%{{bugs}}" and the rest>',
"fmrival": '<transform set name=pkg.fmri -> print test of "%(value)" ... or is it?>',
"fmrinoval": '<transform set name=pkg.fmri -> print test of "%(valuee)" ... or is it?>',
Expand Down Expand Up @@ -527,7 +528,7 @@ def test_11(self):
# ... or an action ...
self.pkgmogrify([self.transforms["emitaction"], source_file])
self.assertMatch(
"^depend fmri=wombat/[email protected],5.11-0.101 type=incorporate"
"^depend fmri=pkg://tp/wombat/[email protected],5.11-0.101 type=incorporate"
)

# Recursive transforms shouldn't blow up.
Expand All @@ -550,7 +551,7 @@ def test_12(self):
source_file = os.path.join(self.test_root, "source_file2")

expect = r'^test of "{0}" ... or is it\?$'
fmri = "wombat/[email protected],5.11-0.101"
fmri = "pkg://tp/wombat/[email protected],5.11-0.101"

# Simple %() replacement
self.pkgmogrify([self.transforms["fmrival"], source_file])
Expand Down Expand Up @@ -625,9 +626,12 @@ def test_13(self):
# Simple valued
self.pkgmogrify([self.transforms["pkg.fmri"], source_file])
self.assertMatch(
'^pkg attr "wombat/[email protected],5.11-0.101" and ' "the rest$"
'^pkg attr "pkg://tp/wombat/[email protected],5.11-0.101" and ' "the rest$"
)

self.pkgmogrify([self.transforms["pkg.fmri.name"], source_file])
self.assertMatch('^pkg attr "wombat/heaven" and ' "the rest$")

# List valued
self.pkgmogrify([self.transforms["pkg.bugs"], source_file])
self.assertMatch('^pkg attr "12345 54321 13524" and the rest$')
Expand Down

0 comments on commit 4c0b4e2

Please sign in to comment.