Add --binpkgs-missing option to equery list to print installed packages that
authorfuzzyray <fuzzyray@gentoo.org>
Thu, 23 Sep 2010 22:15:38 +0000 (22:15 -0000)
committerfuzzyray <fuzzyray@gentoo.org>
Thu, 23 Sep 2010 22:15:38 +0000 (22:15 -0000)
do not have a corresponding binary package built.

svn path=/trunk/gentoolkit/; revision=815

pym/gentoolkit/dbapi.py
pym/gentoolkit/equery/list_.py
pym/gentoolkit/helpers.py

index 2866214c385d8b53bbab5aa78df3c39d4074c824..fbf0bc4286131a0ebb480fce7b93832e7ddc9cf0 100644 (file)
@@ -9,7 +9,7 @@
 
 import portage
 
-#bindb = portage.db[portage.root]["bintree"].dbapi
+BINDB = portage.db[portage.root]["bintree"].dbapi
 PORTDB = portage.db[portage.root]["porttree"].dbapi
 VARDB = portage.db[portage.root]["vartree"].dbapi
 #virtuals = portage.db[portage.root]["virtuals"]
index d783e02726c8db92c06a1af01fba4c54267c2240..941827f5b8ff5cac04221ba5075981e4a79c8500 100644 (file)
@@ -21,6 +21,7 @@ import gentoolkit
 import gentoolkit.pprinter as pp
 from gentoolkit.equery import format_options, mod_usage, CONFIG
 from gentoolkit.helpers import get_installed_cpvs
+from gentoolkit.helpers import get_bintree_cpvs
 from gentoolkit.package import PackageFormatter, FORMAT_TMPL_VARS
 from gentoolkit.query import Query
 
@@ -36,7 +37,8 @@ QUERY_OPTS = {
        "include_mask_reason": False,
        "is_regex": False,
        "show_progress": (not CONFIG['quiet']),
-       "package_format": None
+       "package_format": None,
+       "binpkgs-missing": False
 }
 
 # =========
@@ -71,6 +73,7 @@ def print_help(with_description=True):
        print(format_options((
                (" -h, --help", "display this help message"),
                (" -d, --duplicates", "list only installed duplicate packages"),
+               (" -b, --missing-binpkgs", "list only installed packages without a corresponding binary package"),
                (" -f, --full-regex", "query is a regular expression"),
                (" -m, --mask-reason", "include reason for package mask"),
                (" -I, --exclude-installed",
@@ -102,6 +105,20 @@ def get_duplicates(matches):
        return result
 
 
+def get_binpkgs_missing(matches):
+       """Return only packages that do not have a corresponding binary package."""
+
+       result = []
+       binary_packages = set(get_bintree_cpvs())
+       matched_packages = set(x.cpv for x in matches)
+       missing_binary_packages = set(matched_packages.difference(binary_packages))
+
+       for pkg in matches:
+               if pkg.cpv in missing_binary_packages:
+                       result.append(pkg)
+       return result
+
+
 def parse_module_options(module_opts):
        """Parse module options and update QUERY_OPTS"""
 
@@ -129,6 +146,8 @@ def parse_module_options(module_opts):
                        print()
                elif opt in ('-d', '--duplicates'):
                        QUERY_OPTS['duplicates'] = True
+               elif opt in ('-b', '--binpkgs-missing'):
+                       QUERY_OPTS['binpkgs-missing'] = True
                elif opt in ('-F', '--format'):
                        QUERY_OPTS["package_format"] = posarg
 
@@ -136,7 +155,7 @@ def parse_module_options(module_opts):
 def main(input_args):
        """Parse input and run the program"""
 
-       short_opts = "hdefiImopF:" # -i, -e were options for default actions
+       short_opts = "hdbefiImopF:" # -i, -e were options for default actions
 
        # 04/09: djanderson
        # --all is no longer needed. Kept for compatibility.
@@ -144,7 +163,7 @@ def main(input_args):
        # --exact-name is no longer needed. Kept for compatibility.
        long_opts = ('help', 'all', 'installed', 'exclude-installed',
                'mask-reason', 'portage-tree', 'overlay-tree', 'format=', 'full-regex',
-               'exact-name', 'duplicates')
+               'exact-name', 'duplicates', 'binpkgs-missing')
 
        try:
                module_opts, queries = gnu_getopt(input_args, short_opts, long_opts)
@@ -156,8 +175,8 @@ def main(input_args):
 
        parse_module_options(module_opts)
 
-       # Only search installed packages when listing duplicate packages
-       if QUERY_OPTS["duplicates"]:
+       # Only search installed packages when listing duplicate or missing binary packages
+       if QUERY_OPTS["duplicates"] or QUERY_OPTS["binpkgs-missing"]:
                QUERY_OPTS["in_installed"] = True
                QUERY_OPTS["in_porttree"] = False
                QUERY_OPTS["in_overlay"] = False
@@ -178,6 +197,10 @@ def main(input_args):
                if QUERY_OPTS["duplicates"]:
                        matches = get_duplicates(matches)
 
+               # Find missing binary packages
+               if QUERY_OPTS["binpkgs-missing"]:
+                       matches = get_binpkgs_missing(matches)
+
                matches.sort()
 
                #
index c1c6788b827fced27d4c4c00ae3bee441d91122f..ab0cdbd4891f416acb1abc5bfb367a3f26b9b28f 100644 (file)
@@ -16,6 +16,7 @@ __all__ = (
        'get_cpvs',
        'get_installed_cpvs',
        'get_uninstalled_cpvs',
+       'get_bintree_cpvs',
        'uniqify',
 )
 __docformat__ = 'epytext'
@@ -35,7 +36,7 @@ from gentoolkit import pprinter as pp
 from gentoolkit import errors
 from gentoolkit.atom import Atom
 from gentoolkit.cpv import CPV
-from gentoolkit.dbapi import PORTDB, VARDB
+from gentoolkit.dbapi import BINDB, PORTDB, VARDB
 from gentoolkit.versionmatch import VersionMatch
 # This has to be imported below to stop circular import.
 #from gentoolkit.package import Package
@@ -430,6 +431,25 @@ def get_installed_cpvs(predicate=None):
                yield cpv
 
 
+def get_bintree_cpvs(predicate=None):
+       """Get all binary packages available. Optionally apply a predicate.
+
+       @type predicate: function
+       @param predicate: a function to filter the package list with
+       @rtype: generator
+       @return: a generator that yields unsorted binary package cat/pkg-ver strings
+               from BINDB
+       """
+
+       if predicate:
+               installed_cps = iter(x for x in BINDB.cp_all() if predicate(x))
+       else:
+               installed_cps = BINDB.cp_all()
+
+       for cpv in chain.from_iterable(BINDB.cp_list(x) for x in installed_cps):
+               yield cpv
+
+       
 def print_file(path):
        """Display the contents of a file."""