summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/_emerge/actions.py20
-rw-r--r--pym/portage/tests/resolver/ResolverPlayground.py3
-rw-r--r--pym/portage/tests/resolver/test_depclean.py88
3 files changed, 109 insertions, 2 deletions
diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py
index 92eb18b74..07b5d7b9e 100644
--- a/pym/_emerge/actions.py
+++ b/pym/_emerge/actions.py
@@ -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")
diff --git a/pym/portage/tests/resolver/ResolverPlayground.py b/pym/portage/tests/resolver/ResolverPlayground.py
index be1c29470..e3253e4af 100644
--- a/pym/portage/tests/resolver/ResolverPlayground.py
+++ b/pym/portage/tests/resolver/ResolverPlayground.py
@@ -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:
diff --git a/pym/portage/tests/resolver/test_depclean.py b/pym/portage/tests/resolver/test_depclean.py
index 89e7a8aa3..4ea24e728 100644
--- a/pym/portage/tests/resolver/test_depclean.py
+++ b/pym/portage/tests/resolver/test_depclean.py
@@ -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()