Filter out environment groups unmatch given arch
JIRA: RHELCMP-7926 Signed-off-by: Haibo Lin <hlin@redhat.com>
This commit is contained in:
parent
aabf8faea0
commit
6c280f2c46
@ -96,7 +96,7 @@ def main():
|
||||
f.filter_environments(opts.arch, opts.variant, opts.arch_only_environments)
|
||||
|
||||
if not opts.no_cleanup:
|
||||
f.cleanup(opts.keep_empty_group, opts.lookaside_group)
|
||||
f.cleanup(opts.arch, opts.keep_empty_group, opts.lookaside_group)
|
||||
|
||||
if opts.remove_categories:
|
||||
f.remove_categories()
|
||||
|
@ -177,9 +177,9 @@ class CompsFilter(object):
|
||||
for i in self.tree.xpath("//*[@xml:lang]"):
|
||||
i.getparent().remove(i)
|
||||
|
||||
def filter_environment_groups(self, lookaside_groups=[]):
|
||||
def filter_environment_groups(self, arch, lookaside_groups=[]):
|
||||
"""
|
||||
Remove undefined groups from environments.
|
||||
Remove undefined groups or groups not matching given arch from environments.
|
||||
"""
|
||||
all_groups = self.tree.xpath("/comps/group/id/text()") + lookaside_groups
|
||||
for environment in self.tree.xpath("/comps/environment"):
|
||||
@ -187,6 +187,12 @@ class CompsFilter(object):
|
||||
if group.text not in all_groups:
|
||||
group.getparent().remove(group)
|
||||
|
||||
for group in environment.xpath("grouplist/groupid[@arch]"):
|
||||
value = group.attrib.get("arch")
|
||||
values = [v for v in re.split(r"[, ]+", value) if v]
|
||||
if arch not in values:
|
||||
group.getparent().remove(group)
|
||||
|
||||
def remove_empty_environments(self):
|
||||
"""
|
||||
Remove all environments without groups.
|
||||
@ -212,7 +218,7 @@ class CompsFilter(object):
|
||||
)
|
||||
file_obj.write(b"\n")
|
||||
|
||||
def cleanup(self, keep_groups=[], lookaside_groups=[]):
|
||||
def cleanup(self, arch, keep_groups=[], lookaside_groups=[]):
|
||||
"""
|
||||
Remove empty groups, categories and environment from the comps file.
|
||||
Groups given in ``keep_groups`` will be preserved even if empty.
|
||||
@ -223,7 +229,7 @@ class CompsFilter(object):
|
||||
self.remove_empty_groups(keep_groups)
|
||||
self.filter_category_groups()
|
||||
self.remove_empty_categories()
|
||||
self.filter_environment_groups(lookaside_groups)
|
||||
self.filter_environment_groups(arch, lookaside_groups)
|
||||
self.remove_empty_environments()
|
||||
|
||||
|
||||
|
@ -118,7 +118,7 @@
|
||||
<display_order>10</display_order>
|
||||
<grouplist>
|
||||
<groupid>core</groupid>
|
||||
<groupid>standard</groupid>
|
||||
<groupid arch="x86_64">standard</groupid>
|
||||
<groupid>basic-desktop</groupid>
|
||||
</grouplist>
|
||||
<optionlist>
|
||||
|
@ -196,22 +196,22 @@ class CompsFilterTest(unittest.TestCase):
|
||||
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-removed-environments.xml"))
|
||||
|
||||
def test_cleanup(self):
|
||||
self.filter.cleanup()
|
||||
self.filter.cleanup("ppc64le")
|
||||
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-cleanup.xml"))
|
||||
|
||||
def test_cleanup_after_filter(self):
|
||||
self.filter.filter_packages("ppc64le", None)
|
||||
self.filter.cleanup()
|
||||
self.filter.cleanup("ppc64le")
|
||||
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-cleanup-filter.xml"))
|
||||
|
||||
def test_cleanup_after_filter_keep_group(self):
|
||||
self.filter.filter_packages("ppc64le", None)
|
||||
self.filter.cleanup(["standard"])
|
||||
self.filter.cleanup("ppc64le", ["standard"])
|
||||
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-cleanup-keep.xml"))
|
||||
|
||||
def test_cleanup_all(self):
|
||||
self.filter.filter_packages("ppc64le", None)
|
||||
self.filter.filter_groups("ppc64le", None)
|
||||
self.filter.filter_environments("ppc64le", None)
|
||||
self.filter.cleanup()
|
||||
self.filter.cleanup("ppc64le")
|
||||
self.assertOutput(os.path.join(FIXTURE_DIR, "comps-cleanup-all.xml"))
|
||||
|
Loading…
Reference in New Issue
Block a user