`ImageId=`
-: Matches against the configured image ID. If this condition is used and no
- image ID has been explicitly configured yet, this condition fails. Multiple
- image IDs may be specified, separated by spaces. If multiple image IDs are
- specified, the condition is satisfied if the configured image ID equals any of
- the specified image IDs.
+: Matches against the configured image ID, supporting globs. If this condition
+ is used and no image ID has been explicitly configured yet, this condition
+ fails. Multiple image IDs may be specified, separated by spaces. If multiple
+ image IDs are specified, the condition is satisfied if the configured image ID
+ equals any of the specified image IDs.
`ImageVersion=`
delimiter: str,
*,
unescape: bool = False,
+ allow_globs: bool = False,
all: bool = False,
parse: Callable[[str], Any] = str,
) -> ConfigMatchCallback:
values = value.replace(delimiter, "\n").split("\n")
for v in values:
- m = getattr(namespace, dest) == parse(v)
+ current_value = getattr(namespace, dest)
+ comparison_value = parse(v)
+ if allow_globs:
+ # check if the option has been set, since fnmatch wants strings
+ if isinstance(current_value, str):
+ m = fnmatch.fnmatchcase(current_value, comparison_value)
+ else:
+ m = False
+ else:
+ m = current_value == comparison_value
if not all and m:
return True
),
MkosiConfigSetting(
dest="image_id",
- match=config_make_list_matcher(delimiter=" "),
+ match=config_make_list_matcher(delimiter=" ", allow_globs=True),
section="Output",
),
MkosiConfigSetting(
"""
)
)
+ child4 = Path("mkosi.conf.d/child4.conf")
+ child4.write_text(
+ dedent(
+ """\
+ [Match]
+ ImageId=image*
+
+ [Content]
+ Packages=testpkg4
+ """
+ )
+ )
conf = parse([])
assert "testpkg1" in conf.packages
if image1 == image2:
assert "testpkg2" in conf.packages
assert "testpkg3" in conf.packages
-
+ assert "testpkg4" in conf.packages
@pytest.mark.parametrize(