From a217eea24e3a0c2cfda5a0b32fe7e34ce75ed732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 9 Apr 2018 14:55:24 +0200 Subject: [PATCH] Allow filtering comps for different variants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We already filter for arches, so this just extends the filter to work with variants as well. Signed-off-by: Lubomír Sedlář --- bin/comps_filter | 8 +- pungi/phases/init.py | 1 + pungi/wrappers/comps.py | 13 +++- tests/data/dummy-comps.xml | 4 +- tests/fixtures/comps-cleanup-filter.xml | 4 +- tests/fixtures/comps-cleanup-keep.xml | 8 +- tests/fixtures/comps-cleanup.xml | 8 +- .../comps-filtered-environments-variant.xml | 60 ++++++++++++++ .../fixtures/comps-filtered-environments.xml | 8 +- .../comps-filtered-groups-variant.xml | 61 +++++++++++++++ tests/fixtures/comps-filtered-groups.xml | 4 +- .../comps-filtered-packages-variant.xml | 78 +++++++++++++++++++ tests/fixtures/comps-filtered-packages.xml | 8 +- tests/fixtures/comps-removed-categories.xml | 8 +- tests/fixtures/comps-removed-environments.xml | 6 +- tests/fixtures/comps-removed-langpacks.xml | 8 +- tests/fixtures/comps-removed-translations.xml | 8 +- tests/fixtures/comps.xml.in | 8 +- tests/test_comps_wrapper.py | 29 +++++-- tests/test_initphase.py | 4 + 20 files changed, 281 insertions(+), 55 deletions(-) create mode 100644 tests/fixtures/comps-filtered-environments-variant.xml create mode 100644 tests/fixtures/comps-filtered-groups-variant.xml create mode 100644 tests/fixtures/comps-filtered-packages-variant.xml diff --git a/bin/comps_filter b/bin/comps_filter index dee907fd..4b6c5ccf 100755 --- a/bin/comps_filter +++ b/bin/comps_filter @@ -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) diff --git a/pungi/phases/init.py b/pungi/phases/init.py index c9470f2c..a8dcc967 100644 --- a/pungi/phases/init.py +++ b/pungi/phases/init.py @@ -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) diff --git a/pungi/wrappers/comps.py b/pungi/wrappers/comps.py index f7ea7b2f..b36f67ec 100644 --- a/pungi/wrappers/comps.py +++ b/pungi/wrappers/comps.py @@ -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): """ diff --git a/tests/data/dummy-comps.xml b/tests/data/dummy-comps.xml index 18544aa5..92e99086 100644 --- a/tests/data/dummy-comps.xml +++ b/tests/data/dummy-comps.xml @@ -33,8 +33,8 @@ false true - dummy-elinks - dummy-tftp + dummy-elinks + dummy-tftp diff --git a/tests/fixtures/comps-cleanup-filter.xml b/tests/fixtures/comps-cleanup-filter.xml index 1c2e61c1..45415bd2 100644 --- a/tests/fixtures/comps-cleanup-filter.xml +++ b/tests/fixtures/comps-cleanup-filter.xml @@ -20,8 +20,8 @@ false true - dummy-elinks - dummy-tftp + dummy-elinks + dummy-tftp diff --git a/tests/fixtures/comps-cleanup-keep.xml b/tests/fixtures/comps-cleanup-keep.xml index 638c34b6..61ea302b 100644 --- a/tests/fixtures/comps-cleanup-keep.xml +++ b/tests/fixtures/comps-cleanup-keep.xml @@ -13,7 +13,7 @@ Dummy-firefox - + standard Standard Common set of utilities that extend the minimal installation. @@ -28,8 +28,8 @@ false true - dummy-elinks - dummy-tftp + dummy-elinks + dummy-tftp @@ -45,7 +45,7 @@ - + desktop Desktop Desktop. diff --git a/tests/fixtures/comps-cleanup.xml b/tests/fixtures/comps-cleanup.xml index 442676a7..39b97b08 100644 --- a/tests/fixtures/comps-cleanup.xml +++ b/tests/fixtures/comps-cleanup.xml @@ -14,7 +14,7 @@ dummy-icedtea-web - + standard Standard Common set of utilities that extend the minimal installation. @@ -31,8 +31,8 @@ false true - dummy-elinks - dummy-tftp + dummy-elinks + dummy-tftp @@ -48,7 +48,7 @@ - + desktop Desktop Desktop. diff --git a/tests/fixtures/comps-filtered-environments-variant.xml b/tests/fixtures/comps-filtered-environments-variant.xml new file mode 100644 index 00000000..3061e425 --- /dev/null +++ b/tests/fixtures/comps-filtered-environments-variant.xml @@ -0,0 +1,60 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + dummy-icedtea-web + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + dummy-lvm2 + + + + text-internet + Text-based Internet + This group includes text-based email, Web, and chat clients. These applications do not require the X Window System. + false + true + + dummy-elinks + dummy-tftp + + + + + + + apps + Applications + Toepassings + Applications to perform a variety of tasks + ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ + 20 + + firefox + + + + empty-cat + A dummy category + This should be filtered out + 20 + + + + diff --git a/tests/fixtures/comps-filtered-environments.xml b/tests/fixtures/comps-filtered-environments.xml index 090db058..87beeb64 100644 --- a/tests/fixtures/comps-filtered-environments.xml +++ b/tests/fixtures/comps-filtered-environments.xml @@ -14,7 +14,7 @@ dummy-icedtea-web - + standard Standard Common set of utilities that extend the minimal installation. @@ -31,11 +31,11 @@ false true - dummy-elinks - dummy-tftp + dummy-elinks + dummy-tftp - + desktop Desktop Desktop. diff --git a/tests/fixtures/comps-filtered-groups-variant.xml b/tests/fixtures/comps-filtered-groups-variant.xml new file mode 100644 index 00000000..5201748f --- /dev/null +++ b/tests/fixtures/comps-filtered-groups-variant.xml @@ -0,0 +1,61 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + dummy-icedtea-web + + + + minimal + Minimal install + Минимална инсталация + Basic functionality. + Основна функционалност. + 99 + + core + + + + + + desktop + Desktop + Desktop. + 10 + + standard + + + + + + + apps + Applications + Toepassings + Applications to perform a variety of tasks + ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ + 20 + + firefox + + + + empty-cat + A dummy category + This should be filtered out + 20 + + + + diff --git a/tests/fixtures/comps-filtered-groups.xml b/tests/fixtures/comps-filtered-groups.xml index 7d1cabfe..c1401384 100644 --- a/tests/fixtures/comps-filtered-groups.xml +++ b/tests/fixtures/comps-filtered-groups.xml @@ -14,7 +14,7 @@ dummy-icedtea-web - + standard Standard Common set of utilities that extend the minimal installation. @@ -37,7 +37,7 @@ - + desktop Desktop Desktop. diff --git a/tests/fixtures/comps-filtered-packages-variant.xml b/tests/fixtures/comps-filtered-packages-variant.xml new file mode 100644 index 00000000..d8fa819c --- /dev/null +++ b/tests/fixtures/comps-filtered-packages-variant.xml @@ -0,0 +1,78 @@ + + + + + core + Core + Kern + Smallest possible installation + Kleinste moontlike installasie + true + false + + Dummy-firefox + + + + standard + Standard + Common set of utilities that extend the minimal installation. + false + true + + + + text-internet + Text-based Internet + This group includes text-based email, Web, and chat clients. These applications do not require the X Window System. + false + true + + dummy-elinks + + + + minimal + Minimal install + Минимална инсталация + Basic functionality. + Основна функционалност. + 99 + + core + + + + + + desktop + Desktop + Desktop. + 10 + + standard + + + + + + + apps + Applications + Toepassings + Applications to perform a variety of tasks + ﺖﻄﺒﻴﻗﺎﺗ ﺖﻗﻮﻣ ﺐﻤﻫﺎﻣ ﻢﻧﻮﻋﺓ + 20 + + firefox + + + + empty-cat + A dummy category + This should be filtered out + 20 + + + + diff --git a/tests/fixtures/comps-filtered-packages.xml b/tests/fixtures/comps-filtered-packages.xml index b55dbe1d..a7d8daae 100644 --- a/tests/fixtures/comps-filtered-packages.xml +++ b/tests/fixtures/comps-filtered-packages.xml @@ -13,7 +13,7 @@ Dummy-firefox - + standard Standard Common set of utilities that extend the minimal installation. @@ -28,8 +28,8 @@ false true - dummy-elinks - dummy-tftp + dummy-elinks + dummy-tftp @@ -45,7 +45,7 @@ - + desktop Desktop Desktop. diff --git a/tests/fixtures/comps-removed-categories.xml b/tests/fixtures/comps-removed-categories.xml index 442676a7..39b97b08 100644 --- a/tests/fixtures/comps-removed-categories.xml +++ b/tests/fixtures/comps-removed-categories.xml @@ -14,7 +14,7 @@ dummy-icedtea-web - + standard Standard Common set of utilities that extend the minimal installation. @@ -31,8 +31,8 @@ false true - dummy-elinks - dummy-tftp + dummy-elinks + dummy-tftp @@ -48,7 +48,7 @@ - + desktop Desktop Desktop. diff --git a/tests/fixtures/comps-removed-environments.xml b/tests/fixtures/comps-removed-environments.xml index c1ed0ccc..3061e425 100644 --- a/tests/fixtures/comps-removed-environments.xml +++ b/tests/fixtures/comps-removed-environments.xml @@ -14,7 +14,7 @@ dummy-icedtea-web - + standard Standard Common set of utilities that extend the minimal installation. @@ -31,8 +31,8 @@ false true - dummy-elinks - dummy-tftp + dummy-elinks + dummy-tftp diff --git a/tests/fixtures/comps-removed-langpacks.xml b/tests/fixtures/comps-removed-langpacks.xml index fbd6388d..ecf3f690 100644 --- a/tests/fixtures/comps-removed-langpacks.xml +++ b/tests/fixtures/comps-removed-langpacks.xml @@ -14,7 +14,7 @@ dummy-icedtea-web - + standard Standard Common set of utilities that extend the minimal installation. @@ -31,8 +31,8 @@ false true - dummy-elinks - dummy-tftp + dummy-elinks + dummy-tftp @@ -48,7 +48,7 @@ - + desktop Desktop Desktop. diff --git a/tests/fixtures/comps-removed-translations.xml b/tests/fixtures/comps-removed-translations.xml index 104c381d..c3256925 100644 --- a/tests/fixtures/comps-removed-translations.xml +++ b/tests/fixtures/comps-removed-translations.xml @@ -12,7 +12,7 @@ dummy-icedtea-web - + standard Standard Common set of utilities that extend the minimal installation. @@ -29,8 +29,8 @@ false true - dummy-elinks - dummy-tftp + dummy-elinks + dummy-tftp @@ -44,7 +44,7 @@ - + desktop Desktop Desktop. diff --git a/tests/fixtures/comps.xml.in b/tests/fixtures/comps.xml.in index 8ae80cbd..67500a32 100644 --- a/tests/fixtures/comps.xml.in +++ b/tests/fixtures/comps.xml.in @@ -14,7 +14,7 @@ dummy-icedtea-web - + standard Standard Common set of utilities that extend the minimal installation. @@ -31,8 +31,8 @@ false true - dummy-elinks - dummy-tftp + dummy-elinks + dummy-tftp @@ -48,7 +48,7 @@ - + desktop Desktop Desktop. diff --git a/tests/test_comps_wrapper.py b/tests/test_comps_wrapper.py index fab0322f..09e5e397 100644 --- a/tests/test_comps_wrapper.py +++ b/tests/test_comps_wrapper.py @@ -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')) diff --git a/tests/test_initphase.py b/tests/test_initphase.py index f541af26..5451b872 100644 --- a/tests/test_initphase.py +++ b/tests/test_initphase.py @@ -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,