#!/usr/bin/python -O # Copyright 1999-2006 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id$ import sys # This block ensures that ^C interrupts are handled quietly. try: import signal def exithandler(signum, frame): signal.signal(signal.SIGINT, signal.SIG_IGN) signal.signal(signal.SIGTERM, signal.SIG_IGN) sys.exit(1) signal.signal(signal.SIGINT, exithandler) signal.signal(signal.SIGTERM, exithandler) except KeyboardInterrupt: sys.exit(1) import os import types #----------------------------------------------------------------------------- # # To add functionality to this tool, add a function below. # # The format for functions is: # # def function(argv): # """ # # """ # # # "argv" is an array of the command line parameters provided after the command. # # Make sure you document the function in the right format. The documentation # is used to display help on the function. # # You do not need to add the function to any lists, this tool is introspective, # and will automaticly add a command by the same name as the function! # def has_version(argv): """ Return code 0 if it's available, 1 otherwise. """ if (len(argv) < 2): print "ERROR: insufficient parameters!" sys.exit(2) try: mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1]) if mylist: sys.exit(0) else: sys.exit(1) except KeyError: sys.exit(1) has_version.uses_root = True def best_version(argv): """ Returns category/package-version (without .ebuild). """ if (len(argv) < 2): print "ERROR: insufficient parameters!" sys.exit(2) try: mylist=portage.db[argv[0]]["vartree"].dbapi.match(argv[1]) print portage.best(mylist) except KeyError: sys.exit(1) best_version.uses_root = True def mass_best_version(argv): """ []+ Returns category/package-version (without .ebuild). """ if (len(argv) < 2): print "ERROR: insufficient parameters!" sys.exit(2) try: for pack in argv[1:]: mylist=portage.db[argv[0]]["vartree"].dbapi.match(pack) print pack+":"+portage.best(mylist) except KeyError: sys.exit(1) mass_best_version.uses_root = True def metadata(argv): """ []+ Returns metadata values for the specified package. """ if (len(argv) < 4): print >> sys.stderr, "ERROR: insufficient parameters!" sys.exit(2) root, pkgtype, pkgspec = argv[0:3] metakeys = argv[3:] type_map = { "ebuild":"porttree", "binary":"bintree", "installed":"vartree"} if pkgtype not in type_map: print >> sys.stderr, "Unrecognized package type: '%s'" % pkgtype sys.exit(1) trees = portage.db if os.path.realpath(root) == os.path.realpath(portage.settings["ROOT"]): root = portage.settings["ROOT"] # contains the normalized $ROOT try: values = trees[root][type_map[pkgtype]].dbapi.aux_get( pkgspec, metakeys) for value in values: print value except KeyError: print >> sys.stderr, "Package not found: '%s'" % pkgspec sys.exit(1) metadata.uses_root = True def best_visible(argv): """ []+ Returns category/package-version (without .ebuild). """ if (len(argv) < 2): print "ERROR: insufficient parameters!" sys.exit(2) try: mylist=portage.db[argv[0]]["porttree"].dbapi.match(argv[1]) visible=portage.best(mylist) if visible: print visible sys.exit(0) else: sys.exit(1) except KeyError: sys.exit(1) best_visible.uses_root = True def mass_best_visible(argv): """ []+ Returns category/package-version (without .ebuild). """ if (len(argv) < 2): print "ERROR: insufficient parameters!" sys.exit(2) try: for pack in argv[1:]: mylist=portage.db[argv[0]]["porttree"].dbapi.match(pack) print pack+":"+portage.best(mylist) except KeyError: sys.exit(1) mass_best_visible.uses_root = True def all_best_visible(argv): """ Returns all best_visible packages (without .ebuild). """ if (len(argv) < 1): print "ERROR: insufficient parameters!" #print portage.db[argv[0]]["porttree"].dbapi.cp_all() for pkg in portage.db[argv[0]]["porttree"].dbapi.cp_all(): mybest=portage.best(portage.db[argv[0]]["porttree"].dbapi.match(pkg)) if mybest: print mybest all_best_visible.uses_root = True def match(argv): """ Returns \n seperated list of category/package-version """ if (len(argv) < 2): print "ERROR: insufficient parameters!" sys.exit(2) try: print "\n".join(portage.db[argv[0]]["vartree"].dbapi.match(argv[1])) except ValueError, e: # Multiple matches thrown from cpv_expand pkgs = e.args[0] # An error has occurred so we writemsg to stderr and exit nonzero. portage.writemsg("The following packages available:\n", noiselevel=-1) for pkg in pkgs: portage.writemsg("* %s\n" % pkg, noiselevel=-1) portage.writemsg("\nPlease use a more specific atom.\n", noiselevel=-1) sys.exit(1) except KeyError, e: portage.writemsg("%s\n" % str(e), noiselevel=-1) sys.exit(1) match.uses_root = True def vdb_path(argv): """ Returns the path used for the var(installed) package database for the set environment/configuration options. """ print portage.root+portage.VDB_PATH def gentoo_mirrors(argv): """ Returns the mirrors set to use in the portage configuration. """ print portage.settings["GENTOO_MIRRORS"] def portdir(argv): """ Returns the PORTDIR path. """ print portage.settings["PORTDIR"] def config_protect(argv): """ Returns the CONFIG_PROTECT paths. """ print portage.settings["CONFIG_PROTECT"] def config_protect_mask(argv): """ Returns the CONFIG_PROTECT_MASK paths. """ print portage.settings["CONFIG_PROTECT_MASK"] def portdir_overlay(argv): """ Returns the PORTDIR_OVERLAY path. """ print portage.settings["PORTDIR_OVERLAY"] def pkgdir(argv): """ Returns the PKGDIR path. """ print portage.settings["PKGDIR"] def distdir(argv): """ Returns the DISTDIR path. """ print portage.settings["DISTDIR"] def envvar(argv): """+ Returns a specific environment variable as exists prior to ebuild.sh. Similar to: emerge --verbose --info | egrep '^=' """ verbose = "-v" in argv if verbose: argv.pop(argv.index("-v")) if len(argv) == 0: print "ERROR: insufficient parameters!" sys.exit(2) for arg in argv: if verbose: print arg +"='"+ portage.settings[arg] +"'" else: print portage.settings[arg] def get_repos(argv): """ Returns all repos with names (repo_name file) argv[0] = $ROOT """ if len(argv) < 1: print "ERROR: insufficient parameters!" sys.exit(2) print " ".join(portage.db[argv[0]]["porttree"].dbapi.getRepositories()) def get_repo_path(argv): """ + Returns the path to the repo named argv[1], argv[0] = $ROOT """ if len(argv) < 2: print "ERROR: insufficient parameters!" sys.exit(2) for arg in arvg[1:]: print portage.db[argv[0]]["porttree"].dbapi.getRepositoryPath(argv[1]) def list_preserved_libs(argv): """ Print a list of libraries preserved during a package update in the form package: path. Returns 0 if no preserved libraries could be found, 1 otherwise. """ if len(argv) != 1: print "ERROR: wrong number of arguments" sys.exit(2) mylibs = portage.db[argv[0]]["vartree"].dbapi.plib_registry.getPreservedLibs() rValue = 0 for cpv in mylibs: print cpv, for path in mylibs[cpv]: print path, rValue = 1 print return rValue list_preserved_libs.uses_root = True #----------------------------------------------------------------------------- # # DO NOT CHANGE CODE BEYOND THIS POINT - IT'S NOT NEEDED! # def usage(argv): rev="$Revision: 1.13.2.1 $" ver= rev.split(' ')[1] print ">>> Portage information query tool -- version "+ver print ">>> Usage: portageq [