Port to libmodulemd v2
Fixes: https://pagure.io/pungi/issue/1225 JIRA: COMPOSE-3662 Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
62c6d4ddcf
commit
61e3cb0ef1
14 changed files with 143 additions and 132 deletions
|
|
@ -927,12 +927,38 @@ def parse_koji_event(event):
|
|||
|
||||
|
||||
def iter_module_defaults(path):
|
||||
"""Given a path to a directory with yaml files, yield each module default in there.
|
||||
"""Given a path to a directory with yaml files, yield each module default
|
||||
in there as a pair (module_name, ModuleDefaults instance).
|
||||
"""
|
||||
# It is really tempting to merge all the module indexes into a single one
|
||||
# and work with it. However that does not allow for detecting conflicting
|
||||
# defaults. That should not happen in practice, but better safe than sorry.
|
||||
# Once libmodulemd can report the error, this code can be simplifed by a
|
||||
# lot. It's implemented in
|
||||
# https://github.com/fedora-modularity/libmodulemd/commit/3087e4a5c38a331041fec9b6b8f1a372f9ffe64d
|
||||
# and released in 2.6.0
|
||||
for file in glob.glob(os.path.join(path, "*.yaml")):
|
||||
for mmddef in Modulemd.objects_from_file(file):
|
||||
if isinstance(mmddef, Modulemd.Defaults):
|
||||
yield mmddef
|
||||
index = Modulemd.ModuleIndex()
|
||||
index.update_from_file(file, strict=False)
|
||||
for module_name in index.get_module_names():
|
||||
yield module_name, index.get_module(module_name).get_defaults()
|
||||
|
||||
|
||||
def collect_module_defaults(defaults_dir, modules_to_load=None, mod_index=None):
|
||||
"""Load module defaults into index.
|
||||
|
||||
If `modules_to_load` is passed in, it should be a set of module names. Only
|
||||
defaults for these modules will be loaded.
|
||||
|
||||
If `mod_index` is passed in, it will be updated and returned. If it was
|
||||
not, a new ModuleIndex will be created and returned
|
||||
"""
|
||||
mod_index = mod_index or Modulemd.ModuleIndex()
|
||||
for module_name, defaults in iter_module_defaults(defaults_dir):
|
||||
if not modules_to_load or module_name in modules_to_load:
|
||||
mod_index.add_defaults(defaults)
|
||||
|
||||
return mod_index
|
||||
|
||||
|
||||
def load_config(file_path, defaults={}):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue