diff --git a/bin/comps_filter b/bin/comps_filter
index 63b6516f..dee907fd 100755
--- a/bin/comps_filter
+++ b/bin/comps_filter
@@ -44,11 +44,7 @@ def main():
f.filter_environments(opts.arch, opts.arch_only_environments)
if not opts.no_cleanup:
- f.remove_empty_groups(keep_empty=opts.keep_empty_group)
- f.filter_category_groups()
- f.remove_empty_categories()
- f.filter_environment_groups()
- f.remove_empty_environments()
+ f.cleanup(opts.keep_empty_group)
if opts.remove_categories:
f.remove_categories()
diff --git a/pungi/wrappers/comps.py b/pungi/wrappers/comps.py
index 19243f58..f6848c29 100644
--- a/pungi/wrappers/comps.py
+++ b/pungi/wrappers/comps.py
@@ -189,6 +189,17 @@ class CompsFilter(object):
self.tree.write(file_obj, pretty_print=self.reindent, xml_declaration=True, encoding=self.encoding)
file_obj.write(b"\n")
+ def cleanup(self, keep_groups=[]):
+ """
+ Remove empty groups, categories and environment from the comps file.
+ Groups given in ``keep_groups`` will be preserved even if empty.
+ """
+ self.remove_empty_groups(keep_groups)
+ self.filter_category_groups()
+ self.remove_empty_categories()
+ self.filter_environment_groups()
+ self.remove_empty_environments()
+
class CompsWrapper(object):
"""
diff --git a/tests/fixtures/comps-cleanup-all.xml b/tests/fixtures/comps-cleanup-all.xml
new file mode 100644
index 00000000..98014690
--- /dev/null
+++ b/tests/fixtures/comps-cleanup-all.xml
@@ -0,0 +1,19 @@
+
+
+
+
+ core
+ Core
+ Kern
+ Smallest possible installation
+ Kleinste moontlike installasie
+ true
+ false
+
+ Dummy-firefox
+
+
+
+
+
+
diff --git a/tests/fixtures/comps-cleanup-filter.xml b/tests/fixtures/comps-cleanup-filter.xml
new file mode 100644
index 00000000..1c2e61c1
--- /dev/null
+++ b/tests/fixtures/comps-cleanup-filter.xml
@@ -0,0 +1,43 @@
+
+
+
+
+ core
+ Core
+ Kern
+ Smallest possible installation
+ Kleinste moontlike installasie
+ true
+ false
+
+ Dummy-firefox
+
+
+
+ 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
+
+
+
+ minimal
+ Minimal install
+ Минимална инсталация
+ Basic functionality.
+ Основна функционалност.
+ 99
+
+ core
+
+
+
+
+
+
+
+
diff --git a/tests/fixtures/comps-cleanup-keep.xml b/tests/fixtures/comps-cleanup-keep.xml
new file mode 100644
index 00000000..638c34b6
--- /dev/null
+++ b/tests/fixtures/comps-cleanup-keep.xml
@@ -0,0 +1,60 @@
+
+
+
+
+ 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
+ dummy-tftp
+
+
+
+ minimal
+ Minimal install
+ Минимална инсталация
+ Basic functionality.
+ Основна функционалност.
+ 99
+
+ core
+
+
+
+
+
+ desktop
+ Desktop
+ Desktop.
+ 10
+
+ standard
+
+
+
+
+
+
diff --git a/tests/fixtures/comps-cleanup.xml b/tests/fixtures/comps-cleanup.xml
new file mode 100644
index 00000000..442676a7
--- /dev/null
+++ b/tests/fixtures/comps-cleanup.xml
@@ -0,0 +1,63 @@
+
+
+
+
+ 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
+
+
+
+ minimal
+ Minimal install
+ Минимална инсталация
+ Basic functionality.
+ Основна функционалност.
+ 99
+
+ core
+
+
+
+
+
+ desktop
+ Desktop
+ Desktop.
+ 10
+
+ standard
+
+
+
+
+
+
diff --git a/tests/fixtures/comps-filtered-environments.xml b/tests/fixtures/comps-filtered-environments.xml
new file mode 100644
index 00000000..090db058
--- /dev/null
+++ b/tests/fixtures/comps-filtered-environments.xml
@@ -0,0 +1,69 @@
+
+
+
+
+ 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
+
+
+
+ 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
new file mode 100644
index 00000000..7d1cabfe
--- /dev/null
+++ b/tests/fixtures/comps-filtered-groups.xml
@@ -0,0 +1,71 @@
+
+
+
+
+ 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
+
+
+
+ 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
new file mode 100644
index 00000000..b55dbe1d
--- /dev/null
+++ b/tests/fixtures/comps-filtered-packages.xml
@@ -0,0 +1,79 @@
+
+
+
+
+ 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
+ dummy-tftp
+
+
+
+ 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-removed-categories.xml b/tests/fixtures/comps-removed-categories.xml
new file mode 100644
index 00000000..442676a7
--- /dev/null
+++ b/tests/fixtures/comps-removed-categories.xml
@@ -0,0 +1,63 @@
+
+
+
+
+ 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
+
+
+
+ minimal
+ Minimal install
+ Минимална инсталация
+ Basic functionality.
+ Основна функционалност.
+ 99
+
+ core
+
+
+
+
+
+ desktop
+ Desktop
+ Desktop.
+ 10
+
+ standard
+
+
+
+
+
+
diff --git a/tests/fixtures/comps-removed-environments.xml b/tests/fixtures/comps-removed-environments.xml
new file mode 100644
index 00000000..c1ed0ccc
--- /dev/null
+++ b/tests/fixtures/comps-removed-environments.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-removed-langpacks.xml b/tests/fixtures/comps-removed-langpacks.xml
new file mode 100644
index 00000000..fbd6388d
--- /dev/null
+++ b/tests/fixtures/comps-removed-langpacks.xml
@@ -0,0 +1,79 @@
+
+
+
+
+ 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
+
+
+
+ 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-removed-translations.xml b/tests/fixtures/comps-removed-translations.xml
new file mode 100644
index 00000000..104c381d
--- /dev/null
+++ b/tests/fixtures/comps-removed-translations.xml
@@ -0,0 +1,76 @@
+
+
+
+
+ core
+ Core
+ Smallest possible installation
+ 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
+
+
+
+ minimal
+ Minimal install
+ Basic functionality.
+ 99
+
+ core
+
+
+
+
+
+ desktop
+ Desktop
+ Desktop.
+ 10
+
+ standard
+
+
+
+
+
+
+ apps
+ Applications
+ 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.xml.in b/tests/fixtures/comps.xml.in
new file mode 100644
index 00000000..8ae80cbd
--- /dev/null
+++ b/tests/fixtures/comps.xml.in
@@ -0,0 +1,82 @@
+
+
+
+
+ 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
+
+
+
+ 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/test_comps_wrapper.py b/tests/test_comps_wrapper.py
index 48d91fa1..fab0322f 100644
--- a/tests/test_comps_wrapper.py
+++ b/tests/test_comps_wrapper.py
@@ -12,7 +12,7 @@ import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
-from pungi.wrappers.comps import CompsWrapper
+from pungi.wrappers.comps import CompsWrapper, CompsFilter
from tests.helpers import FIXTURE_DIR
COMPS_FILE = os.path.join(FIXTURE_DIR, 'comps.xml')
@@ -97,3 +97,70 @@ class CompsWrapperTest(unittest.TestCase):
self.assertIn(
'Package dummy-bash in group core has unknown type',
str(ctx.exception))
+
+
+COMPS_IN_FILE = os.path.join(FIXTURE_DIR, 'comps.xml.in')
+
+
+class CompsFilterTest(unittest.TestCase):
+ def setUp(self):
+ self.filter = CompsFilter(COMPS_IN_FILE, reindent=True)
+ self.output = tempfile.NamedTemporaryFile(prefix='comps-filter-test-')
+
+ def assertOutput(self, filepath):
+ self.filter.write(self.output)
+ self.output.flush()
+ with open(self.output.name, 'r') as f:
+ actual = f.read().strip()
+ with open(filepath, 'r') as f:
+ expected = f.read().strip()
+ self.assertEqual(expected, actual)
+
+ def test_filter_packages(self):
+ self.filter.filter_packages('ppc64le')
+ self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-packages.xml'))
+
+ def test_filter_groups(self):
+ self.filter.filter_groups('ppc64le')
+ self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-groups.xml'))
+
+ def test_filter_environments(self):
+ self.filter.filter_environments('ppc64le')
+ self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-filtered-environments.xml'))
+
+ def test_remove_categories(self):
+ self.filter.remove_categories()
+ self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-categories.xml'))
+
+ def test_remove_langpacks(self):
+ self.filter.remove_langpacks()
+ self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-langpacks.xml'))
+
+ def test_remove_translations(self):
+ self.filter.remove_translations()
+ self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-translations.xml'))
+
+ def test_remove_environments(self):
+ self.filter.remove_environments()
+ self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-removed-environments.xml'))
+
+ def test_cleanup(self):
+ self.filter.cleanup()
+ self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup.xml'))
+
+ def test_cleanup_after_filter(self):
+ self.filter.filter_packages('ppc64le')
+ 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.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.cleanup()
+ self.assertOutput(os.path.join(FIXTURE_DIR, 'comps-cleanup-all.xml'))