Allow filtering comps for different variants

We already filter for arches, so this just extends the filter to work
with variants as well.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2018-04-09 14:55:24 +02:00
parent d7021c5688
commit a217eea24e
20 changed files with 281 additions and 55 deletions

View File

@ -34,14 +34,16 @@ def main():
parser.add_argument("--no-reindent", default=False, action="store_true",
help="don't re-indent the output")
parser.add_argument("comps_file", metavar='COMPS_FILE')
parser.add_argument('--variant',
help='filter groups and packages according to variant name')
opts = parser.parse_args()
with open(opts.comps_file, "rb") as file_obj:
f = CompsFilter(file_obj, reindent=not opts.no_reindent)
f.filter_packages(opts.arch, opts.arch_only_packages)
f.filter_groups(opts.arch, opts.arch_only_groups)
f.filter_environments(opts.arch, opts.arch_only_environments)
f.filter_packages(opts.arch, opts.variant, opts.arch_only_packages)
f.filter_groups(opts.arch, opts.variant, opts.arch_only_groups)
f.filter_environments(opts.arch, opts.variant, opts.arch_only_environments)
if not opts.no_cleanup:
f.cleanup(opts.keep_empty_group)

View File

@ -118,6 +118,7 @@ def write_variant_comps(compose, arch, variant):
compose.log_debug(msg)
run(["comps_filter", "--arch=%s" % arch, "--keep-empty-group=conflicts",
"--keep-empty-group=conflicts-%s" % variant.uid.lower(),
"--variant=%s" % variant.uid,
"--output=%s" % comps_file, compose.paths.work.comps(arch="global")])
comps = CompsWrapper(comps_file)

View File

@ -79,29 +79,36 @@ class CompsFilter(object):
# remove the attribute
del elem.attrib[attr_name]
def filter_packages(self, arch, only_arch=False):
def filter_packages(self, arch, variant, only_arch=False):
"""
Filter packages according to arch.
If only_arch is set, then only packages for the specified arch are preserved.
Multiple arches separated by comma can be specified in the XML.
"""
self._filter_elements_by_attr("/comps/group/packagelist/packagereq", 'arch', arch, only_arch)
if variant:
self._filter_elements_by_attr("/comps/group/packagelist/packagereq",
'variant', variant, only_arch)
def filter_groups(self, arch, only_arch=False):
def filter_groups(self, arch, variant, only_arch=False):
"""
Filter groups according to arch.
If only_arch is set, then only groups for the specified arch are preserved.
Multiple arches separated by comma can be specified in the XML.
"""
self._filter_elements_by_attr("/comps/group", 'arch', arch, only_arch)
if variant:
self._filter_elements_by_attr("/comps/group", 'variant', variant, only_arch)
def filter_environments(self, arch, only_arch=False):
def filter_environments(self, arch, variant, only_arch=False):
"""
Filter environments according to arch.
If only_arch is set, then only environments for the specified arch are preserved.
Multiple arches separated by comma can be specified in the XML.
"""
self._filter_elements_by_attr("/comps/environment", 'arch', arch, only_arch)
if variant:
self._filter_elements_by_attr("/comps/environment", 'variant', variant, only_arch)
def filter_category_groups(self):
"""

View File

@ -33,8 +33,8 @@
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
<packagereq type="optional" variant="Server">dummy-elinks</packagereq>
<packagereq type="optional" variant="Client">dummy-tftp</packagereq>
</packagelist>
</group>

View File

@ -20,8 +20,8 @@
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
<packagereq type="optional" variant="Server">dummy-elinks</packagereq>
<packagereq type="optional" variant="Client">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">

View File

@ -13,7 +13,7 @@
<packagereq>Dummy-firefox</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<group arch="ppc64le" variant="Client">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
@ -28,8 +28,8 @@
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
<packagereq type="optional" variant="Server">dummy-elinks</packagereq>
<packagereq type="optional" variant="Client">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
@ -45,7 +45,7 @@
<optionlist>
</optionlist>
</environment>
<environment>
<environment variant="Server">
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>

View File

@ -14,7 +14,7 @@
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<group arch="ppc64le" variant="Client">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
@ -31,8 +31,8 @@
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
<packagereq type="optional" variant="Server">dummy-elinks</packagereq>
<packagereq type="optional" variant="Client">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
@ -48,7 +48,7 @@
<optionlist>
</optionlist>
</environment>
<environment>
<environment variant="Server">
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>

View File

@ -0,0 +1,60 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq arch="ppc64le">Dummy-firefox</packagereq>
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le" variant="Client">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq arch="x86_64">dummy-lvm2</packagereq>
</packagelist>
</group>
<group arch="x86_64">
<id>text-internet</id>
<name>Text-based Internet</name>
<description>This group includes text-based email, Web, and chat clients. These applications do not require the X Window System.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional" variant="Server">dummy-elinks</packagereq>
<packagereq type="optional" variant="Client">dummy-tftp</packagereq>
</packagelist>
</group>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
<category>
<id>apps</id>
<name>Applications</name>
<name xml:lang="af">Toepassings</name>
<description>Applications to perform a variety of tasks</description>
<description xml:lang="ar">ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ</description>
<display_order>20</display_order>
<grouplist>
<groupid>firefox</groupid>
</grouplist>
</category>
<category>
<id>empty-cat</id>
<name>A dummy category</name>
<description>This should be filtered out</description>
<display_order>20</display_order>
<grouplist>
</grouplist>
</category>
</comps>

View File

@ -14,7 +14,7 @@
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<group arch="ppc64le" variant="Client">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
@ -31,11 +31,11 @@
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
<packagereq type="optional" variant="Server">dummy-elinks</packagereq>
<packagereq type="optional" variant="Client">dummy-tftp</packagereq>
</packagelist>
</group>
<environment>
<environment variant="Server">
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>

View File

@ -0,0 +1,61 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq arch="ppc64le">Dummy-firefox</packagereq>
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
<optionlist>
</optionlist>
</environment>
<environment variant="Server">
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>standard</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
<category>
<id>apps</id>
<name>Applications</name>
<name xml:lang="af">Toepassings</name>
<description>Applications to perform a variety of tasks</description>
<description xml:lang="ar">ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ</description>
<display_order>20</display_order>
<grouplist>
<groupid>firefox</groupid>
</grouplist>
</category>
<category>
<id>empty-cat</id>
<name>A dummy category</name>
<description>This should be filtered out</description>
<display_order>20</display_order>
<grouplist>
</grouplist>
</category>
</comps>

View File

@ -14,7 +14,7 @@
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group>
<group variant="Client">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
@ -37,7 +37,7 @@
<optionlist>
</optionlist>
</environment>
<environment>
<environment variant="Server">
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>

View File

@ -0,0 +1,78 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd">
<comps>
<group>
<id>core</id>
<name>Core</name>
<name xml:lang="af">Kern</name>
<description>Smallest possible installation</description>
<description xml:lang="af">Kleinste moontlike installasie</description>
<default>true</default>
<uservisible>false</uservisible>
<packagelist>
<packagereq>Dummy-firefox</packagereq>
</packagelist>
</group>
<group arch="ppc64le" variant="Client">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist/>
</group>
<group arch="x86_64">
<id>text-internet</id>
<name>Text-based Internet</name>
<description>This group includes text-based email, Web, and chat clients. These applications do not require the X Window System.</description>
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
<id>minimal</id>
<name>Minimal install</name>
<name xml:lang="bg">Минимална инсталация</name>
<description>Basic functionality.</description>
<description xml:lang="bg">Основна функционалност.</description>
<display_order>99</display_order>
<grouplist>
<groupid>core</groupid>
</grouplist>
<optionlist>
</optionlist>
</environment>
<environment variant="Server">
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>
<display_order>10</display_order>
<grouplist>
<groupid>standard</groupid>
</grouplist>
</environment>
<langpacks>
<match install="LabPlot-doc-%s" name="LabPlot-doc"/>
</langpacks>
<category>
<id>apps</id>
<name>Applications</name>
<name xml:lang="af">Toepassings</name>
<description>Applications to perform a variety of tasks</description>
<description xml:lang="ar">ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ</description>
<display_order>20</display_order>
<grouplist>
<groupid>firefox</groupid>
</grouplist>
</category>
<category>
<id>empty-cat</id>
<name>A dummy category</name>
<description>This should be filtered out</description>
<display_order>20</display_order>
<grouplist>
</grouplist>
</category>
</comps>

View File

@ -13,7 +13,7 @@
<packagereq>Dummy-firefox</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<group arch="ppc64le" variant="Client">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
@ -28,8 +28,8 @@
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
<packagereq type="optional" variant="Server">dummy-elinks</packagereq>
<packagereq type="optional" variant="Client">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
@ -45,7 +45,7 @@
<optionlist>
</optionlist>
</environment>
<environment>
<environment variant="Server">
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>

View File

@ -14,7 +14,7 @@
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<group arch="ppc64le" variant="Client">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
@ -31,8 +31,8 @@
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
<packagereq type="optional" variant="Server">dummy-elinks</packagereq>
<packagereq type="optional" variant="Client">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
@ -48,7 +48,7 @@
<optionlist>
</optionlist>
</environment>
<environment>
<environment variant="Server">
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>

View File

@ -14,7 +14,7 @@
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<group arch="ppc64le" variant="Client">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
@ -31,8 +31,8 @@
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
<packagereq type="optional" variant="Server">dummy-elinks</packagereq>
<packagereq type="optional" variant="Client">dummy-tftp</packagereq>
</packagelist>
</group>
<langpacks>

View File

@ -14,7 +14,7 @@
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<group arch="ppc64le" variant="Client">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
@ -31,8 +31,8 @@
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
<packagereq type="optional" variant="Server">dummy-elinks</packagereq>
<packagereq type="optional" variant="Client">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
@ -48,7 +48,7 @@
<optionlist>
</optionlist>
</environment>
<environment>
<environment variant="Server">
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>

View File

@ -12,7 +12,7 @@
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<group arch="ppc64le" variant="Client">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
@ -29,8 +29,8 @@
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
<packagereq type="optional" variant="Server">dummy-elinks</packagereq>
<packagereq type="optional" variant="Client">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
@ -44,7 +44,7 @@
<optionlist>
</optionlist>
</environment>
<environment>
<environment variant="Server">
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>

View File

@ -14,7 +14,7 @@
<packagereq arch="x86_64">dummy-icedtea-web</packagereq>
</packagelist>
</group>
<group arch="ppc64le">
<group arch="ppc64le" variant="Client">
<id>standard</id>
<name>Standard</name>
<description>Common set of utilities that extend the minimal installation.</description>
@ -31,8 +31,8 @@
<default>false</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type="optional">dummy-elinks</packagereq>
<packagereq type="optional">dummy-tftp</packagereq>
<packagereq type="optional" variant="Server">dummy-elinks</packagereq>
<packagereq type="optional" variant="Client">dummy-tftp</packagereq>
</packagelist>
</group>
<environment arch="x86_64">
@ -48,7 +48,7 @@
<optionlist>
</optionlist>
</environment>
<environment>
<environment variant="Server">
<id>desktop</id>
<name>Desktop</name>
<description>Desktop.</description>

View File

@ -114,20 +114,33 @@ class CompsFilterTest(unittest.TestCase):
actual = f.read().strip()
with open(filepath, 'r') as f:
expected = f.read().strip()
self.maxDiff = None
self.assertEqual(expected, actual)
def test_filter_packages(self):
self.filter.filter_packages('ppc64le')
self.filter.filter_packages('ppc64le', None)
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-packages.xml'))
def test_filter_packages_with_variant(self):
self.filter.filter_packages('ppc64le', 'Server')
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-packages-variant.xml'))
def test_filter_groups(self):
self.filter.filter_groups('ppc64le')
self.filter.filter_groups('ppc64le', None)
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-groups.xml'))
def test_filter_groups_with_variant(self):
self.filter.filter_groups('ppc64le', 'Server')
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-groups-variant.xml'))
def test_filter_environments(self):
self.filter.filter_environments('ppc64le')
self.filter.filter_environments('ppc64le', None)
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-environments.xml'))
def test_filter_environments_variant(self):
self.filter.filter_environments('ppc64le', 'Client')
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-environments-variant.xml'))
def test_remove_categories(self):
self.filter.remove_categories()
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-categories.xml'))
@ -149,18 +162,18 @@ class CompsFilterTest(unittest.TestCase):
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup.xml'))
def test_cleanup_after_filter(self):
self.filter.filter_packages('ppc64le')
self.filter.filter_packages('ppc64le', None)
self.filter.cleanup()
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-filter.xml'))
def test_cleanup_after_filter_keep_group(self):
self.filter.filter_packages('ppc64le')
self.filter.filter_packages('ppc64le', None)
self.filter.cleanup(['standard'])
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-keep.xml'))
def test_cleanup_all(self):
self.filter.filter_packages('ppc64le')
self.filter.filter_groups('ppc64le')
self.filter.filter_environments('ppc64le')
self.filter.filter_packages('ppc64le', None)
self.filter.filter_groups('ppc64le', None)
self.filter.filter_environments('ppc64le', None)
self.filter.cleanup()
self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-all.xml'))

View File

@ -206,6 +206,7 @@ class TestWriteVariantComps(PungiTestCase):
self.assertEqual(run.mock_calls,
[mock.call(['comps_filter', '--arch=x86_64', '--keep-empty-group=conflicts',
'--keep-empty-group=conflicts-server',
'--variant=Server',
'--output=%s/work/x86_64/comps/comps-Server.x86_64.xml' % self.topdir,
self.topdir + '/work/global/comps/comps-global.xml'])])
self.assertEqual(CompsWrapper.call_args_list,
@ -230,6 +231,7 @@ class TestWriteVariantComps(PungiTestCase):
self.assertEqual(run.mock_calls,
[mock.call(['comps_filter', '--arch=x86_64', '--keep-empty-group=conflicts',
'--keep-empty-group=conflicts-server',
'--variant=Server',
'--output=%s/work/x86_64/comps/comps-Server.x86_64.xml' % self.topdir,
self.topdir + '/work/global/comps/comps-global.xml'])])
self.assertEqual(CompsWrapper.call_args_list,
@ -255,6 +257,7 @@ class TestWriteVariantComps(PungiTestCase):
self.assertEqual(run.mock_calls,
[mock.call(['comps_filter', '--arch=x86_64', '--keep-empty-group=conflicts',
'--keep-empty-group=conflicts-server',
'--variant=Server',
'--output=%s/work/x86_64/comps/comps-Server.x86_64.xml' % self.topdir,
self.topdir + '/work/global/comps/comps-global.xml'])])
self.assertEqual(CompsWrapper.call_args_list,
@ -278,6 +281,7 @@ class TestWriteVariantComps(PungiTestCase):
self.assertEqual(run.mock_calls,
[mock.call(['comps_filter', '--arch=x86_64', '--keep-empty-group=conflicts',
'--keep-empty-group=conflicts-server',
'--variant=Server',
'--output=%s/work/x86_64/comps/comps-Server.x86_64.xml' % self.topdir,
self.topdir + '/work/global/comps/comps-global.xml'])])
self.assertEqual(CompsWrapper.call_args_list,