Add --exclude option
authorSebastian Luther <SebastianLuther@gmx.de>
Thu, 29 Apr 2010 05:54:17 +0000 (07:54 +0200)
committerZac Medico <zmedico@gentoo.org>
Thu, 29 Apr 2010 12:54:01 +0000 (05:54 -0700)
man/emerge.1
pym/_emerge/depgraph.py
pym/_emerge/help.py
pym/_emerge/main.py

index f451e2f67c2a9e904c3fdd70d11cdfc8042ba646..a0ba4b70f0615b686206db34d0dac9ebd4f786ca 100644 (file)
@@ -359,6 +359,11 @@ dependency tree, as though no packages are currently
 installed. You should run this with \fB\-\-pretend\fR
 first to make sure the result is what you expect.
 .TP
+.BR "\-\-exclude " ATOMS
+A comma separated list of package names or slot atoms.
+Emerge won't  install any ebuild or binary package that
+matches any of the given package atoms.
+.TP
 .BR "\-\-fail\-clean[=n]"
 Clean up temporary files after a build failure. This is
 particularly useful if you have \fBPORTAGE_TMPDIR\fR on
index c3e180faf75520f2fb4214bc96a3ad310151547c..005c2979c0c924f42c1e012f15fcf0972f53ed23 100644 (file)
@@ -93,6 +93,24 @@ class _frozen_depgraph_config(object):
 
                self._required_set_names = set(["world"])
 
+               self.excluded_pkgs = InternalPackageSet()
+               for x in myopts.get("--exclude", []):
+                       cat = x.cp.split("/")[0]
+                       if cat == "null":
+                               pkgname = x.cp.split("/")[1]
+                               for myroot in trees:
+                                       for tree in ("porttree", "bintree"):
+                                               if tree == "bintree" and not "--usepkg" in myopts:
+                                                       continue
+                                               db = self.trees[myroot][tree].dbapi
+                                               for cat in db.categories:
+                                                       if db.cp_list(cat + "/" + pkgname):
+                                                               atom = portage.dep.Atom(str(x).replace("null", cat))
+                                                               self.excluded_pkgs.add(atom)
+                       else:
+                               self.excluded_pkgs.add(x)
+
+
 class _dynamic_depgraph_config(object):
 
        def __init__(self, depgraph, myparams, allow_backtracking,
@@ -2173,6 +2191,8 @@ class depgraph(object):
                                                mreasons.append('backtracking: %s' % \
                                                        ', '.join(sorted(backtrack_reasons)))
                                                backtrack_mask = True
+                                       if not mreasons and self._frozen_config.excluded_pkgs.findAtomForPackage(pkg):
+                                               mreasons = ["exclude option"]
                                        if mreasons:
                                                masked_pkg_instances.add(pkg)
                                        if atom.use:
@@ -2451,6 +2471,10 @@ class depgraph(object):
                                                # The package has been masked by the backtracking logic
                                                continue
 
+                                       if not pkg.installed and \
+                                               self._frozen_config.excluded_pkgs.findAtomForPackage(pkg):
+                                               continue
+
                                        if dont_miss_updates:
                                                higher_version_rejected = False
                                                for rejected in packages_with_invalid_use_config:
index a62bc08a68e16296c2199df7073d9498cd53c291..bf95a05ebec44794ff58bd259094372bad32eb82 100644 (file)
@@ -378,6 +378,13 @@ def help(myopts, havecolor=1):
                for line in wrap(desc, desc_width):
                        print(desc_indent + line)
                print()
+               print("       " + green("--exclude") + " " + turquoise("ATOMS"))
+               desc = "A comma separated list of package names or slot atoms. " + \
+                       "Emerge won't  install any ebuild or binary package that " + \
+                       "matches any of the given package atoms."
+               for line in wrap(desc, desc_width):
+                       print(desc_indent + line)
+               print()
                print("       "+green("--fail-clean[=n]"))
                desc = "Clean up temporary files after a build failure. This is " + \
                        "particularly useful if you have PORTAGE_TMPDIR on " + \
index 21888f590ca8a2fc3d0d0f6c55e14f69f60cc31f..11dc9a4f0a512f0be64b15aa5764e12ce814a1d3 100644 (file)
@@ -560,6 +560,14 @@ def parse_opts(tmpcmdline, silent=False):
                        "choices" : ("True", "n")
                },
 
+               "--exclude": {
+                       "help"   :"A comma separated list of package names or slot atoms. " + \
+                               "Emerge won't  install any ebuild or binary package that " + \
+                               "matches any of the given package atoms.",
+
+                       "action" : "store"
+               },
+
                "--fail-clean": {
                        "help"    : "clean temp files after build failure",
                        "type"    : "choice",
@@ -724,6 +732,33 @@ def parse_opts(tmpcmdline, silent=False):
        else:
                myoptions.complete_graph = None
 
+       if myoptions.exclude:
+               exclude = []
+               bad_atoms = []
+               for x in myoptions.exclude.split(","):
+                       bad_atom = False
+                       try:
+                               atom = portage.dep.Atom(x)
+                       except portage.exception.InvalidAtom:
+                               try:
+                                       atom = portage.dep.Atom("null/"+x)
+                               except portage.exception.InvalidAtom:
+                                       bad_atom = True
+                       
+                       if bad_atom:
+                               bad_atoms.append(x)
+                       else:
+                               if atom.operator or atom.blocker or atom.use:
+                                       bad_atoms.append(x)
+                               else:
+                                       exclude.append(atom)
+
+               if bad_atoms and not silent:
+                       writemsg("!!! Invalid Atom(s) in --exclude parameter: '%s' (only package names and slot atoms allowed)\n" % \
+                               (",".join(bad_atoms),), noiselevel=-1)
+
+               myoptions.exclude = exclude
+
        if myoptions.fail_clean == "True":
                myoptions.fail_clean = True