Wildcard support for -c/-C
authorSebastian Luther <SebastianLuther@gmx.de>
Mon, 24 Jan 2011 13:40:27 +0000 (14:40 +0100)
committerZac Medico <zmedico@gentoo.org>
Wed, 2 Feb 2011 23:10:06 +0000 (15:10 -0800)
pym/_emerge/actions.py
pym/portage/tests/resolver/ResolverPlayground.py
pym/portage/tests/resolver/test_depclean.py

index 1ea2510d25487ff6630ff3cf66e6c7ce56adcccc..84f75568bb06ca86fac4764426fc4dc6b01c072a 100644 (file)
@@ -31,6 +31,8 @@ from portage.cache.cache_errors import CacheError
 from portage.const import GLOBAL_CONFIG_PATH, NEWS_LIB_PATH
 from portage.const import _ENABLE_DYN_LINK_MAP
 from portage.dbapi.dep_expand import dep_expand
+from portage.dep import Atom, extended_cp_match
+from portage.exception import InvalidAtom
 from portage.output import blue, bold, colorize, create_color_func, darkgreen, \
        red, yellow
 good = create_color_func("GOOD")
@@ -2443,7 +2445,6 @@ def action_sync(settings, trees, mtimedb, myopts, myaction):
 
 def action_uninstall(settings, trees, ldpath_mtimes,
        opts, action, files, spinner):
-
        # For backward compat, some actions do not require leading '='.
        ignore_missing_eq = action in ('clean', 'unmerge')
        root = settings['ROOT']
@@ -2486,6 +2487,28 @@ def action_uninstall(settings, trees, ldpath_mtimes,
                elif x.startswith(SETPREFIX) and action == "deselect":
                        valid_atoms.append(x)
 
+               elif "*" in x:
+                       try:
+                               ext_atom = Atom(x, allow_repo=True, allow_wildcard=True)
+                       except InvalidAtom:
+                               msg = []
+                               msg.append("'%s' is not a valid package atom." % (x,))
+                               msg.append("Please check ebuild(5) for full details.")
+                               writemsg_level("".join("!!! %s\n" % line for line in msg),
+                                       level=logging.ERROR, noiselevel=-1)
+                               return 1
+
+                       for cp in vardb.cp_all():
+                               if extended_cp_match(ext_atom.cp, cp):
+                                       atom = cp
+                                       if ext_atom.slot:
+                                               atom += ":" + ext_atom.slot
+                                       if ext_atom.repo:
+                                               atom += "::" + ext_atom.repo
+
+                                       if vardb.match(atom):
+                                               valid_atoms.append(Atom(atom))
+
                else:
                        msg = []
                        msg.append("'%s' is not a valid package atom." % (x,))
index e3253e4af5ff1b6094ad874ab7a5ca44b9d177d9..1fd5abf67c8f4ca4b976480613c7c77affd10224 100644 (file)
@@ -425,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", InternalPackageSet(initial_atoms=atoms), None)
+                                       options, "depclean", InternalPackageSet(initial_atoms=atoms, allow_wildcard=True), None)
                                result = ResolverPlaygroundDepcleanResult( \
                                        atoms, rval, cleanlist, ordered, req_pkg_count)
                        else:
index 18e0b87e407cb1a94888891500be2dfab5992b56..ba70144b8b8991072a11d9ad4dc42752ca275ef6 100644 (file)
@@ -243,3 +243,43 @@ class DepcleanWithExcludeAndSlotsTestCase(TestCase):
                                self.assertEqual(test_case.test_success, True, test_case.fail_msg)
                finally:
                        playground.cleanup()
+
+class DepcleanAndWildcardsTestCase(TestCase):
+
+       def testDepcleanAndWildcards(self):
+
+               installed = {
+                       "dev-libs/A-1": { "RDEPEND": "dev-libs/B" },
+                       "dev-libs/B-1": {},
+                       }
+
+               test_cases = (
+                       ResolverPlaygroundTestCase(
+                               ["*/*"],
+                               options = {"--depclean": True},
+                               success = True,
+                               cleanlist = ["dev-libs/A-1", "dev-libs/B-1"]),
+                       ResolverPlaygroundTestCase(
+                               ["dev-libs/*"],
+                               options = {"--depclean": True},
+                               success = True,
+                               cleanlist = ["dev-libs/A-1", "dev-libs/B-1"]),
+                       ResolverPlaygroundTestCase(
+                               ["*/A"],
+                               options = {"--depclean": True},
+                               success = True,
+                               cleanlist = ["dev-libs/A-1"]),
+                       ResolverPlaygroundTestCase(
+                               ["*/B"],
+                               options = {"--depclean": True},
+                               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()