Skip to content

Commit 4c0b4e2

Browse files
authored
Merge pull request #497 from citrus-it/pkg.fmri
Add synthetic pkg.fmri.name attribute to pkgmogrify
2 parents f58bac4 + e8d4fcc commit 4c0b4e2

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/man/pkgmogrify.1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
2-
.\" Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
3-
.Dd February 17, 2022
2+
.\" Copyright 2024 OmniOS Community Edition (OmniOSce) Association.
3+
.Dd October 1, 2024
44
.Dt PKGMOGRIFY 1
55
.Os
66
.Sh NAME
@@ -309,6 +309,15 @@ action, or it is treated as
309309
described above.
310310
When the processing reaches the end of the manifest file describing the
311311
package, the attributes are cleared for the next package.
312+
The following synthetic attributes are also automatically generated from
313+
.Sy pkg.fmri
314+
when it is encountered:
315+
.Bl -tag -width Ds
316+
.It Cm pkg.fmri.name
317+
The name of the package, without any scheme, publisher name or version
318+
information, e.g.
319+
.Sq library/libxml2 .
320+
.El
312321
.Pp
313322
It is useful not only to reference package attributes as if they were action
314323
attributes, but also to match on them, and even temporarily modify them.

src/modules/mogrify.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,11 @@ def process_mog(
886886
pkg_attrs.setdefault(name, []).append(value)
887887
else:
888888
pkg_attrs.setdefault(name, []).extend(value)
889+
if name == "pkg.fmri":
890+
pfmri = pkg.fmri.PkgFmri(value)
891+
pkg_attrs.setdefault("pkg.fmri.name", []).append(
892+
pfmri.get_name()
893+
)
889894
comment, a = apply_transforms(
890895
transforms, act, pkg_attrs, verbose, filename, lineno
891896
)

src/tests/cli/t_pkgmogrify.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class TestPkgMogrify(pkg5unittest.CliTestCase):
7070
"""
7171

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

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

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

555556
# Simple %() replacement
556557
self.pkgmogrify([self.transforms["fmrival"], source_file])
@@ -625,9 +626,12 @@ def test_13(self):
625626
# Simple valued
626627
self.pkgmogrify([self.transforms["pkg.fmri"], source_file])
627628
self.assertMatch(
628-
'^pkg attr "wombat/[email protected],5.11-0.101" and ' "the rest$"
629+
'^pkg attr "pkg://tp/wombat/[email protected],5.11-0.101" and ' "the rest$"
629630
)
630631

632+
self.pkgmogrify([self.transforms["pkg.fmri.name"], source_file])
633+
self.assertMatch('^pkg attr "wombat/heaven" and ' "the rest$")
634+
631635
# List valued
632636
self.pkgmogrify([self.transforms["pkg.bugs"], source_file])
633637
self.assertMatch('^pkg attr "12345 54321 13524" and the rest$')

0 commit comments

Comments
 (0)