Simplify iterating over module defaults

There are now two places where we need to do this, so we can simplify
the logic of finding and filtering them.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2018-06-22 09:18:10 +02:00
parent 98e7106f3e
commit 6c14236562
3 changed files with 25 additions and 13 deletions

View File

@ -33,7 +33,12 @@ from kobo.shortcuts import run, relative_path
from ..wrappers.scm import get_dir_from_scm
from ..wrappers.createrepo import CreaterepoWrapper
from .base import PhaseBase
from ..util import find_old_compose, temp_dir, get_arch_variant_data
from ..util import (
find_old_compose,
get_arch_variant_data,
iter_module_defaults,
temp_dir,
)
from pungi import Modulemd
from pungi.arch import tree_arch_to_yum_arch
@ -244,9 +249,8 @@ def create_variant_repo(compose, arch, variant, pkg_type, modules_metadata=None)
modules.append(repo_mmd)
module_names = set([x.get_name() for x in modules])
for mmddeffile in glob.glob(os.path.join(compose.paths.work.module_defaults_dir(), "*.yaml")):
for mmddef in Modulemd.objects_from_file(mmddeffile):
if isinstance(mmddef, Modulemd.Defaults) and mmddef.peek_module_name() in module_names:
for mmddef in iter_module_defaults(compose.paths.work.module_defaults_dir()):
if mmddef.peek_module_name() in module_names:
modules.append(mmddef)
with temp_dir() as tmp_dir:

View File

@ -15,16 +15,14 @@
import collections
import glob
import os
import shutil
from kobo.shortcuts import run
from pungi import Modulemd
from pungi.phases.base import PhaseBase
from pungi.phases.gather import write_prepopulate_file
from pungi.util import temp_dir
from pungi.util import temp_dir, iter_module_defaults
from pungi.wrappers.comps import CompsWrapper
from pungi.wrappers.createrepo import CreaterepoWrapper
from pungi.wrappers.scm import get_dir_from_scm, get_file_from_scm
@ -188,10 +186,8 @@ def validate_module_defaults(path):
:param str path: directory with cloned module defaults
"""
seen_defaults = collections.defaultdict(set)
for file in glob.glob(os.path.join(path, "*.yaml")):
for mmddef in Modulemd.objects_from_file(file):
if not isinstance(mmddef, Modulemd.Defaults):
continue
for mmddef in iter_module_defaults(path):
seen_defaults[mmddef.peek_module_name()].add(mmddef.peek_default_stream())
errors = []

View File

@ -15,6 +15,7 @@
import argparse
import fnmatch
import glob
import json
import subprocess
import os
@ -34,6 +35,8 @@ from six.moves import urllib, range, shlex_quote
from kobo.shortcuts import run, force_list
from productmd.common import get_major_version
from pungi import Modulemd
# Patterns that match all names of debuginfo packages
DEBUG_PATTERNS = ["*-debuginfo", "*-debuginfo-*", "*-debugsource"]
@ -855,3 +858,12 @@ def parse_koji_event(event):
raise argparse.ArgumentTypeError(
"%s is not a number or path to compose with valid Koji event" % event
)
def iter_module_defaults(path):
"""Given a path to a directory with yaml files, yield each module default in there.
"""
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