#!/usr/bin/python # # Copyright 2006 Mike Pagano # Distributed under the terms of the GNU General Public License v2 # # $Header$ # Author: Mike Pagano # # Portions written ripped from # - equery, by Karl Trygve Kalleberg # - gentoolkit.py, by Karl Trygve Kalleberg # __author__ = "Michael Pagano" __email__ = "mpagano@gmail.com" __version__ = "0.0.1" __productname__ = "portpeek" __description__ = "Displays user unmasked ebuilds and installable options from the portage tree" import sys,portage,output sys.path.insert(0, "/usr/lib/gentoolkit/pym") import gentoolkit import portage_const from portage_const import USER_CONFIG_PATH porttree = portage.db[portage.root]["porttree"] settings = portage.config(clone=portage.settings) def printUsage(): # Print full usage information for this tool to the console. print output.white("Usage: ") + output.turquoise(__productname__) + output.yellow(" ") print "where " + output.yellow("") + " is one of" print output.yellow(" -k, --keyword") + " - show matches from portage.keyword only" print output.yellow(" -u, --unmask") + " - show matched from portage.unmask only" print output.yellow(" -m, --mask") + " - show matches from portage.mask only" print output.yellow(" -a, --all") + " - show all matches" print output.yellow(" -V, --version") + " - display version info" def get_keywords(x,var): mytree = porttree r = mytree.dbapi.aux_get(x._cpv,[var]) return r[0] def get_info(filename): pkgs = None try: fd = open(filename) for line in fd.readlines(): line = line.strip(); if len(line) <= 0: continue elif line[0] == "#": continue fields = line.split(" ") if len(fields) > 0: pkgs = gentoolkit.find_packages(fields[0], True) if pkgs != None: for x in pkgs: if not x.is_installed(): continue else: keywords = "%s" % (get_keywords(x,"KEYWORDS").split()) print output.green("Installed: ") + \ output.turquoise(x.get_cpv()) + \ output.yellow(" Keywords " + keywords) all_pkgs = gentoolkit.sort_package_list(gentoolkit.find_packages((x.get_category() + \ "/" + x.get_name()), True)) for y in all_pkgs: if not y.is_installed(): pkgmask = _get_mask_status(y) if ((x.compare_version(y)) < 0): keywords = "%s" % (y.get_env_var("KEYWORDS").split()) if pkgmask > 4: print output.red("Available: " + y.get_cpv() + " Keywords: " + keywords) else: print output.fuscia("Available: " + y.get_cpv() + " Keywords: " + keywords) print x = "" except IOError: print output.red("Could not find file " + filename) def parseArgs(args): # parse arguments for i in xrange(len(args)): x = args[i] if 0: pass elif x in ["-h", "--help"]: return "showhelp" elif x in ["-V", "--version"]: printVersion() sys.exit(0) elif x in ["-k", "--keyword"]: return "keyword" elif x in ["-u", "--unmask"]: return "unmask" elif x in ["-m", "--mask"]: return "mask" elif x in ["-a", "--all"]: return "all" else: break # blatantly stolen from equery def _get_mask_status(pkg): pkgmask = 0 if pkg.is_masked(): pkgmask = pkgmask + 3 keywords = pkg.get_env_var("KEYWORDS").split() if "~" + gentoolkit.settings["ARCH"] in keywords: pkgmask = pkgmask + 1 elif "-*" in keywords or "-" + gentoolkit.settings["ARCH"] in keywords: pkgmask = pkgmask + 2 return pkgmask #print version info def printVersion(): """Print the version of this tool to the console.""" print __productname__ + "(" + __version__ + ") - " + \ __description__ print "Author(s): " + __author__ # main if __name__ == "__main__": command = parseArgs(sys.argv[1:]) if command is None: printUsage() sys.exit(-1) elif command == "keyword": print output.darkyellow("\npackage.keywords:") get_info(USER_CONFIG_PATH + "/package.keywords") elif command == "unmask": print output.darkyellow("\npackage.unmask:") get_info(USER_CONFIG_PATH + "/package.unmask") elif command == "mask": print output.darkyellow("\npackage.mask:") get_info(USER_CONFIG_PATH + "/package.mask") elif command == "all": print output.darkyellow("\npackage.keywords:") get_info(USER_CONFIG_PATH + "/package.keywords") print output.darkyellow("package.unmask:") get_info(USER_CONFIG_PATH + "/package.unmask") print output.darkyellow("package.mask:") get_info(USER_CONFIG_PATH + "/package.mask")