Get --exclude to work with --depclean and --prune
authorSebastian Luther <SebastianLuther@gmx.de>
Tue, 28 Sep 2010 13:14:01 +0000 (15:14 +0200)
committerZac Medico <zmedico@gentoo.org>
Fri, 1 Oct 2010 00:49:20 +0000 (17:49 -0700)
Thanks to forum member 'krinn' for the suggestion

pym/_emerge/actions.py
pym/portage/tests/resolver/ResolverPlayground.py
pym/portage/tests/resolver/test_depclean.py

index 92eb18b740146628ff6fc8ff7b73204251726b38..07b5d7b9ebc08eaf5126fe9b5cb31c18b01e187a 100644 (file)
@@ -623,6 +623,7 @@ def calc_depclean(settings, trees, ldpath_mtimes,
        deselect = myopts.get('--deselect') != 'n'
        required_sets = {}
        required_sets['world'] = psets['world']
+       excluded_set = InternalPackageSet(initial_atoms=myopts.get('--exclude'))
 
        # When removing packages, a temporary version of the world 'selected'
        # set may be used which excludes packages that are intended to be
@@ -675,7 +676,8 @@ def calc_depclean(settings, trees, ldpath_mtimes,
                        # by an argument atom since we don't want to clean any
                        # package if something depends on it.
                        for pkg in vardb:
-                               spinner.update()
+                               if spinner:
+                                       spinner.update()
 
                                try:
                                        if args_set.findAtomForPackage(pkg) is None:
@@ -741,6 +743,22 @@ def calc_depclean(settings, trees, ldpath_mtimes,
                                protected_set.add("=" + pkg.cpv)
                                continue
 
+       if excluded_set:
+               required_sets['__excluded__'] = InternalPackageSet()
+
+               for pkg in vardb:
+                       if spinner:
+                               spinner.update()
+
+                       try:
+                               if excluded_set.findAtomForPackage(pkg):
+                                       required_sets['__excluded__'].add("=" + pkg.cpv)
+                       except portage.exception.InvalidDependString as e:
+                               show_invalid_depstring_notice(pkg,
+                                       pkg.metadata["PROVIDE"], str(e))
+                               del e
+                               required_sets['__excluded__'].add("=" + pkg.cpv)
+
        success = resolver._complete_graph(required_sets={myroot:required_sets})
        writemsg_level("\b\b... done!\n")
 
index be1c2947094d22fb6e488ae6423dc231bf6647f7..e3253e4af5ff1b6094ad874ab7a5ca44b9d177d9 100644 (file)
@@ -14,6 +14,7 @@ from portage.dep import Atom, _repo_separator
 from portage.package.ebuild.config import config
 from portage.package.ebuild.digestgen import digestgen
 from portage._sets import load_default_config
+from portage._sets.base import InternalPackageSet
 from portage.versions import catsplit
 
 import _emerge
@@ -424,7 +425,7 @@ class ResolverPlayground(object):
                        if options.get("--depclean"):
                                rval, cleanlist, ordered, req_pkg_count = \
                                        calc_depclean(self.settings, self.trees, None,
-                                       options, "depclean", atoms, None)
+                                       options, "depclean", InternalPackageSet(initial_atoms=atoms), None)
                                result = ResolverPlaygroundDepcleanResult( \
                                        atoms, rval, cleanlist, ordered, req_pkg_count)
                        else:
index 89e7a8aa339f36b76738195e0d0d62f397d3fcda..4ea24e728a8bd11f1eb8f3af7ddcece532e60fa1 100644 (file)
@@ -117,3 +117,91 @@ class DepcleanWithInstalledMaskedTestCase(TestCase):
                                self.assertEqual(test_case.test_success, True, test_case.fail_msg)
                finally:
                        playground.cleanup()
+
+class DepcleanWithExcludeTestCase(TestCase):
+
+       def testepcleanWithExclude(self):
+
+               installed = {
+                       "dev-libs/A-1": {},
+                       "dev-libs/B-1": { "RDEPEND": "dev-libs/A" },
+                       }
+
+               test_cases = (
+                       #Without --exclude.
+                       ResolverPlaygroundTestCase(
+                               [],
+                               options = {"--depclean": True},
+                               success = True,
+                               cleanlist = ["dev-libs/B-1", "dev-libs/A-1"]),
+                       ResolverPlaygroundTestCase(
+                               ["dev-libs/A"],
+                               options = {"--depclean": True},
+                               success = True,
+                               cleanlist = []),
+                       ResolverPlaygroundTestCase(
+                               ["dev-libs/B"],
+                               options = {"--depclean": True},
+                               success = True,
+                               cleanlist = ["dev-libs/B-1"]),
+
+                       #With --exclude
+                       ResolverPlaygroundTestCase(
+                               [],
+                               options = {"--depclean": True, "--exclude": ["dev-libs/A"]},
+                               success = True,
+                               cleanlist = ["dev-libs/B-1"]),
+                       ResolverPlaygroundTestCase(
+                               ["dev-libs/B"],
+                               options = {"--depclean": True, "--exclude": ["dev-libs/B"]},
+                               success = True,
+                               cleanlist = []),
+                       )
+
+               playground = ResolverPlayground(installed=installed)
+               try:
+                       for test_case in test_cases:
+                               playground.run_TestCase(test_case)
+                               self.assertEqual(test_case.test_success, True, test_case.fail_msg)
+               finally:
+                       playground.cleanup()
+
+class DepcleanWithExcludeAndSlotsTestCase(TestCase):
+
+       def testepcleanWithExcludeAndSlots(self):
+
+               installed = {
+                       "dev-libs/Z-1": { "SLOT": 1},
+                       "dev-libs/Z-2": { "SLOT": 2},
+                       "dev-libs/Y-1": { "RDEPEND": "=dev-libs/Z-1", "SLOT": 1 },
+                       "dev-libs/Y-2": { "RDEPEND": "=dev-libs/Z-2", "SLOT": 2 },
+                       }
+
+               world = [ "dev-libs/Y" ]
+
+               test_cases = (
+                       #Without --exclude.
+                       ResolverPlaygroundTestCase(
+                               [],
+                               options = {"--depclean": True},
+                               success = True,
+                               cleanlist = ["dev-libs/Y-1", "dev-libs/Z-1"]),
+                       ResolverPlaygroundTestCase(
+                               [],
+                               options = {"--depclean": True, "--exclude": ["dev-libs/Z"]},
+                               success = True,
+                               cleanlist = ["dev-libs/Y-1"]),
+                       ResolverPlaygroundTestCase(
+                               [],
+                               options = {"--depclean": True, "--exclude": ["dev-libs/Y"]},
+                               success = True,
+                               cleanlist = []),
+                       )
+
+               playground = ResolverPlayground(installed=installed, world=world)
+               try:
+                       for test_case in test_cases:
+                               playground.run_TestCase(test_case)
+                               self.assertEqual(test_case.test_success, True, test_case.fail_msg)
+               finally:
+                       playground.cleanup()