From 883c1c08db619de8b631735aa6e4f42d85d9a0be Mon Sep 17 00:00:00 2001 From: karltk Date: Wed, 7 Jan 2004 13:21:01 +0000 Subject: More build system updates; renamed gentool to equery svn path=/; revision=49 --- trunk/src/echangelog/ChangeLog | 2 + trunk/src/echangelog/TODO | 0 trunk/src/ekeyword/ChangeLog | 2 + trunk/src/ekeyword/Makefile | 2 +- trunk/src/ekeyword/TODO | 0 trunk/src/equery/AUTHORS | 3 + trunk/src/equery/ChangeLog | 21 + trunk/src/equery/Makefile | 20 + trunk/src/equery/README | 0 trunk/src/equery/TODO | 0 trunk/src/equery/equery | 897 ++++++++++++++++++++++++++++++ trunk/src/equery/equery.1 | 12 + trunk/src/etcat/ChangeLog | 6 + trunk/src/etcat/etcat.1 | 2 +- trunk/src/euse/ChangeLog | 10 +- trunk/src/gentool/AUTHORS | 3 - trunk/src/gentool/ChangeLog | 17 - trunk/src/gentool/Makefile | 20 - trunk/src/gentool/README | 0 trunk/src/gentool/TODO | 0 trunk/src/gentool/gentool | 897 ------------------------------ trunk/src/gentool/gentool-bump-revision | 72 --- trunk/src/gentool/gentool-bump-revision.1 | 20 - trunk/src/gentool/gentool-package-count | 9 - trunk/src/gentool/gentool-package-count.1 | 17 - trunk/src/gentool/gentool-package-size | 138 ----- trunk/src/gentool/gentool-package-size.1 | 44 -- trunk/src/gentool/gentool.1 | 12 - trunk/src/qpkg/ChangeLog | 2 + trunk/src/qpkg/qpkg | 754 ++++++++++++++++++------- trunk/src/qpkg/qpkg.1 | 2 +- trunk/src/revdep-rebuild/Makefile | 2 +- 32 files changed, 1526 insertions(+), 1460 deletions(-) create mode 100644 trunk/src/echangelog/ChangeLog create mode 100644 trunk/src/echangelog/TODO create mode 100644 trunk/src/ekeyword/ChangeLog create mode 100644 trunk/src/ekeyword/TODO create mode 100644 trunk/src/equery/AUTHORS create mode 100644 trunk/src/equery/ChangeLog create mode 100644 trunk/src/equery/Makefile create mode 100644 trunk/src/equery/README create mode 100644 trunk/src/equery/TODO create mode 100755 trunk/src/equery/equery create mode 100644 trunk/src/equery/equery.1 delete mode 100644 trunk/src/gentool/AUTHORS delete mode 100644 trunk/src/gentool/ChangeLog delete mode 100644 trunk/src/gentool/Makefile delete mode 100644 trunk/src/gentool/README delete mode 100644 trunk/src/gentool/TODO delete mode 100755 trunk/src/gentool/gentool delete mode 100755 trunk/src/gentool/gentool-bump-revision delete mode 100644 trunk/src/gentool/gentool-bump-revision.1 delete mode 100755 trunk/src/gentool/gentool-package-count delete mode 100644 trunk/src/gentool/gentool-package-count.1 delete mode 100755 trunk/src/gentool/gentool-package-size delete mode 100644 trunk/src/gentool/gentool-package-size.1 delete mode 100644 trunk/src/gentool/gentool.1 (limited to 'trunk/src') diff --git a/trunk/src/echangelog/ChangeLog b/trunk/src/echangelog/ChangeLog new file mode 100644 index 0000000..6cdc211 --- /dev/null +++ b/trunk/src/echangelog/ChangeLog @@ -0,0 +1,2 @@ +2004-01-07 Karl Trygve Kalleberg + * Added Makefile diff --git a/trunk/src/echangelog/TODO b/trunk/src/echangelog/TODO new file mode 100644 index 0000000..e69de29 diff --git a/trunk/src/ekeyword/ChangeLog b/trunk/src/ekeyword/ChangeLog new file mode 100644 index 0000000..6cdc211 --- /dev/null +++ b/trunk/src/ekeyword/ChangeLog @@ -0,0 +1,2 @@ +2004-01-07 Karl Trygve Kalleberg + * Added Makefile diff --git a/trunk/src/ekeyword/Makefile b/trunk/src/ekeyword/Makefile index ad793bb..487930f 100644 --- a/trunk/src/ekeyword/Makefile +++ b/trunk/src/ekeyword/Makefile @@ -4,7 +4,7 @@ # # $Header$ -include ../../makdefs.mak +include ../../makedefs.mak all: echo "ALBACETE (AL-ba-seet n.) A single surprisingly long hair growing in the middle of nowhere." diff --git a/trunk/src/ekeyword/TODO b/trunk/src/ekeyword/TODO new file mode 100644 index 0000000..e69de29 diff --git a/trunk/src/equery/AUTHORS b/trunk/src/equery/AUTHORS new file mode 100644 index 0000000..9935ef7 --- /dev/null +++ b/trunk/src/equery/AUTHORS @@ -0,0 +1,3 @@ +Karl Trygve Kalleberg + * Initial version + diff --git a/trunk/src/equery/ChangeLog b/trunk/src/equery/ChangeLog new file mode 100644 index 0000000..708cbcf --- /dev/null +++ b/trunk/src/equery/ChangeLog @@ -0,0 +1,21 @@ +2003-01-07 Karl Trygve Kalleberg + * Renamed to equery + * Added Makefile + +2003-12-31 Karl Trygve Kalleberg + * Added which command + * Added check command (not finished) + +2003-12-12 Karl Trygve Kalleberg + * Added size command + * Added depgraph command + +2003-12-11 Karl Trygve Kalleberg + * Added list command + * Added uses command + +2003-10-05 Karl Trygve Kalleberg + * Added files command + * Added belongs command + + diff --git a/trunk/src/equery/Makefile b/trunk/src/equery/Makefile new file mode 100644 index 0000000..77798c6 --- /dev/null +++ b/trunk/src/equery/Makefile @@ -0,0 +1,20 @@ +# Copyright 2003 Karl Trygve Kalleberg +# Copyright 2003 Gentoo Technologies, Inc. +# Distributed under the terms of the GNU General Public License v2 +# +# $Header$ + +include ../../makedefs.mak + +all: + echo "YADDLETHORPE (vb.) (Of offended pooves.) To exit huffily from a boutique." + +dist: + mkdir -p ../../$(distdir)/src/gentool/ + cp {Makefile,AUTHORS,README,TODO,ChangeLog,gentool,gentool.1} ../../$(distdir)/src/gentool/ + +install: + install -m 0755 gentool $(bindir)/ + install -d $(docdir)/gentool + install -m 0644 {README,AUTHORS} $(docdir)/gentool/ + install -m 0644 gentool.1 $(mandir)/ diff --git a/trunk/src/equery/README b/trunk/src/equery/README new file mode 100644 index 0000000..e69de29 diff --git a/trunk/src/equery/TODO b/trunk/src/equery/TODO new file mode 100644 index 0000000..e69de29 diff --git a/trunk/src/equery/equery b/trunk/src/equery/equery new file mode 100755 index 0000000..40b2e10 --- /dev/null +++ b/trunk/src/equery/equery @@ -0,0 +1,897 @@ +#! /usr/bin/env python2.2 +# +# Copyright 2003 Karl Trygve Kalleberg +# Copyright 2003 Gentoo Technologies, Inc. +# Distributed under the terms of the GNU General Public License v2 +# +# $Header$ +# Author: Karl Trygve Kalleberg + +__author__ = "Karl Trygve Kalleberg" +__email__ = "karltk@gentoo.org" +__version__ = "0.1.0" +__productname__ = "equery" +__description__ = "Gentoo Package Query Tool" + +import re +import sys +import time +import string +import gentoolkit +from output import * + + +# Auxiliary functions + +def fileAsStr(name, fdesc, showType=0, showMD5=0, showTimestamp=0): + + type = ""; fname = ""; stamp = ""; md5sum = "" + + if fdesc[0] == 'obj': + type = "file" + fname = name + stamp = timestampAsStr(int(fdesc[1])) + md5sum = fdesc[2] + elif fdesc[0] == "dir": + type = "dir" + fname = white(name) + elif fdesc[0] == "sym": + type = "symlink" + stamp = timestampAsStr(int(fdesc[1].replace(")",""))) + tgt = fdesc[2].split()[0] + fname = turquoise(name + " -> " + tgt) + else: + raise "Unknown type: " + fdesc[0] + + s = "" + if showType: + s += "%6s " % type + s += fname + if showTimestamp: + s += stamp + " " + if showMD5: + s += md5sum + " " + return s + +def timestampAsStr(timestamp): + return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)) + + +class Command: + def __init__(self): + pass + def shortHelp(self): + return " - not implemented yet" + def longHelp(self): + return "help for syntax and options" + def perform(self, args): + pass + def parseArgs(self, args): + pass + + +class CmdListFiles(Command): + """List files owned by a particular package""" + def __init__(self): + self.default_options = { + "showType": 0, + "showTimestamp": 0, + "showMD5": 0 + } + + def parseArgs(self,args): + query = "" + need_help = 0 + opts = self.default_options + for x in args: + if x in ["-h", "--help"]: + need_help = 1 + elif x in ["--md5sum"]: + opts["showMD5"] = 1 + elif x in ["--timestamp"]: + opts["showTimestamp"] = 1 + elif x in ["--type"]: + opts["showType"] = 1 + else: + query = x + + if need_help or query == "": + print self.longHelp() + sys.exit(-1) + + return (query, opts) + + def perform(self, args): + + (query, opts) = self.parseArgs(args) + + if Config["verbosityLevel"] >= 3: + print "Searching for packages matching '" + query + "'..." + + pkgs = gentoolkit.find_packages(query) + for x in pkgs: + + if not x.is_installed(): + continue + + if Config["verbosityLevel"] >= 1: + print "Contents of " + x.get_cpv() + ":" + + cnt = x.get_contents() + + for name in cnt: + print fileAsStr(name, + cnt[name], + showType=opts["showType"], + showTimestamp=opts["showTimestamp"], + showMD5=opts["showMD5"]) + + + def longHelp(self): + return "List files owned by a particular package\n" + \ + "\n" + \ + "Syntax:\n" + \ + " " + green("files") + yellow(" packagename<-version>") + "\n" + \ + "\n" + \ + "Note: category and version parts are optional. \n" + \ + "\n" + \ + yellow("") + " is either of: \n" + \ + " " + yellow("--timestamp") + " - append timestamp\n" + \ + " " + yellow("--md5sum") + " - append md5sum\n" + \ + " " + yellow("--type") + " - prepend file type" + def shortHelp(self): + return yellow(" ") + teal("pkgspec") + " - list files owned by " + teal("pkgspec") + + +class CmdListBelongs(Command): + """List all packages owning a particular file""" + def __init__(self): + self.default_opts = { + "category": "*", + "earlyOut": 0 + } + + def parseArgs(self, args): + + query = "" + need_help = 0 + opts = self.default_opts + skip = 0 + + for i in xrange(len(args)): + + if skip: + skip -= 1 + continue + x = args[i] + + if x in ["-h","--help"]: + need_help = 1 + break + elif x in ["-c", "--category"]: + opts["category"] = args[i+1] + skip = 1 + elif x in ["-e", "--earlyout"]: + opts["earlyOut"] = 1 + else: + query = x + + if need_help or query == "": + print self.longHelp() + sys.exit(-1) + + return (query, opts) + + def perform(self, args): + (query, opts) = self.parseArgs(args) + + cat = opts["category"] + filter_fn = None + if cat != "*": + filter_fn = lambda x: x.find(cat+"/")==0 + + if Config["verbosityLevel"] >= 3: + print "Searching for file '" + query + "' in " + cat + "..." + + matches = gentoolkit.find_all_installed_packages(filter_fn) + rx = re.compile(query) + + found = 0 + for pkg in matches: + cnt = pkg.get_contents() + for file in cnt.keys(): + if rx.search(file): + print pkg.get_cpv() + " (" + fileAsStr(file, cnt[file]) + ")" + if opts["earlyOut"]: + found = 1 + break + if found: + break + + def shortHelp(self): + return yellow(" ") + teal("file") + " - list all packages owning " + teal("file") + def longHelp(self): + return "List all packages owning a particular file" + \ + "\n" + \ + "\n" + \ + turquoise("Note: ") + "Normally, only one package will own a file. If multiple packages own the same file, it usually consitutes a problem, and should be reported.\n" + \ + "\n" + \ + "Syntax:\n" + \ + " " + green("belongs") + yellow(" ") + teal("filename") + \ + "\n" + \ + yellow("") + " is either of: \n" + \ + " " + yellow("-c, --category cat") + " - only search in category " + yellow("cat") + "\n" + \ + " " + yellow("-e, --earlyout") + " - stop when first match found\n" + +class CmdDisplayUSEs(Command): + """Advanced report of a package's USE flags""" + def __init__(self): + self.default_opts = { + } + def parseArgs(self, args): + + query = "" + need_help = 0 + opts = self.default_opts + skip = 0 + + for i in xrange(len(args)): + + if skip: + skip -= 1 + continue + x = args[i] + + if x in ["-h","--help"]: + need_help = 1 + break + else: + query = x + + if need_help or query == "": + print self.longHelp() + sys.exit(-1) + + return (query, opts) + + def perform(self, args): + + (query, opts) = self.parseArgs(args) + + matches = gentoolkit.find_packages(query) + + useflags = gentoolkit.settings["USE"].split() + usedesc = {} + uselocaldesc = {} + + # Load global USE flag descriptions + try: + fd = open(gentoolkit.settings["PORTDIR"]+"/profiles/use.desc") + usedesc = {} + for line in fd.readlines(): + if line[0] == "#": + continue + fields = line.split(" - ") + if len(fields) == 2: + usedesc[fields[0].strip()] = fields[1].strip() + except IOError: + if Config["verbosityLevel"] >= 5: + print "Warning: Could not load USE flag descriptions from " + gentoolkit.settings["PORTDIR"] + "/profiles/use.desc" + + # Load local USE flag descriptions + try: + fd = open(gentoolkit.settings["PORTDIR"]+"/profiles/use.local.desc") + for line in fd.readlines(): + if line[0] == "#": + continue + fields = line.split(" - ") + if len(fields) == 2: + catpkguse = re.search("([a-z]+-[a-z]+/.*):(.*)", fields[0]) + if catpkguse: + if not uselocaldesc.has_key(catpkguse.group(1).strip()): + uselocaldesc[catpkguse.group(1).strip()] = {catpkguse.group(2).strip() : fields[1].strip()} + else: + uselocaldesc[catpkguse.group(1).strip()][catpkguse.group(2).strip()] = fields[1].strip() + except IOError: + if Config["verbosityLevel"] >= 5: + print "Warning: Could not load USE flag descriptions from " + gentoolkit.settings["PORTDIR"] + "/profiles/use.desc" + + print "[ Colour Code : " + green("set") + " " + red("unset") + " ]" + print "[ Legend : (U) Col 1 - Current USE flags ]" + print "[ : (I) Col 2 - Installed With USE flags ]" + + # Iterate through matches, printing a report for each package + for p in matches: + if not p.is_installed(): + continue + + bestver = p.get_cpv() + iuse = p.get_env_var("IUSE") + + if iuse: usevar = iuse.split() + else: usevar = [] + + inuse = [] + used = p.get_use_vars().split() + + # store (inuse, inused, flag, desc) + output = [] + + for u in usevar: + inuse = 0 + inused = 0 + try: + desc = usedesc[u] + except KeyError: + try: + desc = uselocaldesc[p][u] + except KeyError: + desc = "" + + if u in useflags: inuse = 1 + if u in used: inused = 1 + + output.append((inuse, inused, u, desc)) + + # pretty print + if output: + print + print white(" U I ") + "[ Found these USE variables in : " + white(bestver) + " ]" + maxflag_len = 0 + for inuse, inused, u, desc in output: + if len(u) > maxflag_len: + maxflag_len = len(u) + + for inuse, inused, u, desc in output: + flag = ["-","+"] + colour = [red, green] + if inuse != inused: + print yellow(" %s %s" % (flag[inuse], flag[inused])), + else: + print " %s %s" % (flag[inuse], flag[inused]), + + print colour[inuse](u.ljust(maxflag_len)), + + # print description + if desc: + print ":", desc + else: + print ": unknown" + else: + print "[ No USE flags found for :", white(p.get_cpv()), "]" + def shortHelp(self): + return yellow(" ") + teal("pkgspec") + " - display USE flags for " + teal("pkgspec") + def longHelp(self): + return "Display USE flags for a given package\n" + \ + "\n" + \ + "Syntax:\n" + \ + " " + green("uses") + yellow(" ") + teal("pkgspec") + \ + "\n" + \ + yellow("") + " is either of: \n" + + +class CmdDisplayDepGraph(Command): + """Display tree graph of deps for pkgQuery""" + + def __init__(self): + self.default_opts = { + "displayUSEFlags": 1, + "fancyFormatting": 1 + } + + def parseArgs(self, args): + + query = "" + need_help = 0 + opts = self.default_opts + skip = 0 + + for i in xrange(len(args)): + + if skip: + skip -= 1 + continue + x = args[i] + + if x in ["-h","--help"]: + need_help = 1 + break + elif x in ["-U","--no-useflags"]: + opts["displayUSEFlags"] = 0 + elif x in ["-l","--linear"]: + opts["fancyFormatting"] = 0 + else: + query = x + + if need_help or query == "": + print self.longHelp() + sys.exit(-1) + + return (query, opts) + + def perform(self, args): + (query, opts) = self.parseArgs(args) + + matches = gentoolkit.find_packages(query) + + for pkg in matches: + + if Config["verbosityLevel"] >= 3: + print "Displaying dependencies for " + pkg.get_cpv() + "\n" + + if not pkg.is_installed(): + continue + self._graph(pkg, opts) + + def _graph(self, pkg, opts, level=0,pkgtbl=[],suffix=""): + + cpv=pkg.get_cpv() + + pfx = "" + if opts["fancyFormatting"]: + pfx = level*" " + "`-- " + print pfx + cpv + suffix + + pkgtbl.append(cpv) + + for x in pkg.get_runtime_deps(): + suffix = "" + cpv = x[2] + pkg = gentoolkit.find_best_match(x[0] + cpv) + if not pkg: + continue + if pkg.get_cpv() in pkgtbl: + continue + if cpv.find("virtual")==0: + suffix += " (" + cpv + ")" + if len(x[1]) and opts["displayUSEFlags"]: + suffix += " [ " + string.join(x[1]) + " ]" + pkgtbl = self._graph(pkg, opts, level+1, pkgtbl, suffix) + return pkgtbl + + def shortHelp(self): + return yellow(" ") + teal("pkgspec") + " - display a dependency tree for " + teal("pkgspec") + def longHelp(self): + return "Display a dependency tree for a given package\n" + \ + "\n" + \ + "Syntax:\n" + \ + " " + green("depgraph") + yellow(" ") + teal("pkgspec") + \ + "\n" + \ + yellow("") + " is either of: \n" + \ + " " + yellow("-U, --no-useflags") + " - do not show USE flags\n" + \ + " " + yellow("-l, --linear") + " - do not use fancy formatting" + +class CmdDisplaySize(Command): + """Display disk size consumed by a package""" + def __init__(self): + self.default_opts = { + "reportSizeInBytes": 0 + } + + def parseArgs(self, args): + + query = "" + need_help = 0 + opts = self.default_opts + skip = 0 + + for i in xrange(len(args)): + + if skip: + skip -= 1 + continue + x = args[i] + + if x in ["-h","--help"]: + need_help = 1 + break + elif x in ["-b","--bytes"]: + opts["reportSizeInBytes"] = 1 + else: + query = x + + if need_help or query == "": + print self.longHelp() + sys.exit(-1) + + return (query, opts) + + def perform(self, args): + (query, opts) = self.parseArgs(args) + + matches = gentoolkit.find_packages(query) + + for pkg in matches: + if not pkg.is_installed(): + continue + + (size, files, uncounted) = pkg.size() + + print turquoise("*") + " " + white(pkg.get_cpv()) + print string.rjust(" Total Files : ",25) + str(files) + + if uncounted: + print string.rjust(" Inaccessible Files : ",25) + str(uncounted) + + sz = "%.2f KiB" % (size/1024.0) + if opts["reportSizeInBytes"]: + sz = str(size) + " bytes" + + print string.rjust("Total Size : ",25) + sz + + + def shortHelp(self): + return yellow(" ") + teal("pkgspec") + " - print size of files contained in package " + teal("pkgspec") + def longHelp(self): + return "Print size total size of files contained in a given package" + \ + "\n" + \ + "Syntax:\n" + \ + " " + green("size") + yellow(" ") + teal("pkgspec") + \ + "\n" + \ + yellow("") + " is either of: \n" + \ + " " + yellow("-b, --bytes") + " - report size in bytes\n" + +class CmdDisplayChanges(Command): + """Display changes for pkgQuery""" + pass + +class CheckException: + def __init__(self, s): + self.s = s + +class CmdCheckIntegrity(Command): + """Check timestamps and md5sums for files owned by pkgspec""" + def __init__(self): + self.default_opts = { + "showSummary" : 1, + "showGoodFiles" : 0, + "showBadFiles" : 1, + "checkTimestamp" : 1, + "checkMD5sum": 1 + } + + def parseArgs(self, args): + + query = "" + need_help = 0 + opts = self.default_opts + skip = 0 + + for i in xrange(len(args)): + if skip: + skip -= 1 + continue + x = args[i] + + if x in ["-h","--help"]: + need_help = 1 + break + else: + query = x + + if need_help or query == "": + print self.longHelp() + sys.exit(-1) + + return (query, opts) + + def checkMD5sum(self, file): + return 1 + + def perform(self, args): + (query, opts) = self.parseArgs(args) + + matches = gentoolkit.find_packages(query) + + for pkg in matches: + if not pkg.is_installed(): + continue + files = pkg.get_contents() + for file in files.keys(): + type = files[file][0] + try: + st = os.lstat(file) + if type == "dir": + if not os.path.isdir(file): + raise CheckException(file + " exists, but is not a directory") + elif type == "obj": + mtime = files[file][1] + if opts["checkTimestamp"]: + if st.st_mtime != int(mtime): + raise CheckException(file + (" has wrong mtime (is %d, should be %s)" % (st.st_mtime, mtime))) + if opts["checkMD5sum"]: + if not self.checkMD5sum(file): + raise CheckException(file + " has incorrect md5sum") + elif type == "sym": + # FIXME: nastry strippery; portage should have this fixed! + t = files[file][2] + i = t.find("(") + target = t[0:i].strip() + if not os.path.islink(file): + raise CheckException(file + " exists, but is not a symlink") + tgt = os.readlink(file) + if tgt != target: + raise CheckException(file + " does not point to " + target) + + else: + print file + print files[file] + print type + raise "Unknown type" + except CheckException, (e): + print e.s + except OSError: + print file + " does not exist" + + def shortHelp(self): + return teal("pkgspec") + " - check package's files against recorded MD5 sums and timestamps" + def longHelp(self): + return "Check package's files against recorded MD5 sums and timestamps" + +class CmdDisplayStatistics(Command): + """Display statistics about installed and uninstalled packages""" + pass + +class CmdWhich(Command): + """Display the filename of the ebuild for a given package + that would be used by Portage with the current configuration.""" + def __init__(self): + self.default_opts = {} + + def parseArgs(self, args): + + query = "" + need_help = 0 + opts = self.default_opts + skip = 0 + + for i in xrange(len(args)): + + if skip: + skip -= 1 + continue + x = args[i] + + if x in ["-h","--help"]: + need_help = 1 + break + else: + query = x + + if need_help or query == "": + print self.longHelp() + sys.exit(-1) + + return (query, opts) + + def perform(self, args): + (query, opts) = self.parseArgs(args) + + matches = gentoolkit.find_packages(query) + + for pkg in matches: + print os.path.normpath(pkg.get_ebuild_path()) + + def shortHelp(self): + return teal("pkgspec") + " - print full path to ebuild for package " + teal("pkgspec") + def longHelp(self): + return "Print full path to ebuild for a given package" + +class CmdListGLSAs(Command): + """List outstanding GLSAs.""" + pass + +class CmdListDepends(Command): + """List all packages directly or indirectly depending on pkgQuery""" + pass + +class CmdListPackages(Command): + """List packages satisfying pkgQuery""" + def __init__(self): + self.default_opts = { + "category": "*", + "includeInstalled": 1, + "includePortTree": 0, + "includeOverlayTree": 0, + "regex": 0 + } + + def parseArgs(self, args): + + query = "" + need_help = 0 + opts = self.default_opts + skip = 0 + + for i in xrange(len(args)): + + if skip: + skip -= 1 + continue + x = args[i] + + if x in ["-h","--help"]: + need_help = 1 + break + elif x in ["-i", "--installed"]: + opts["includeInstalled"] = 1 + elif x in ["-I", "--exclude-installed"]: + opts["includeInstalled"] = 0 + elif x in ["-p", "--portage-tree"]: + opts["includePortTree"] = 1 + elif x in ["-o", "--overlay-tree"]: + opts["includeOverlayTree"] = 1 + else: + query = x + + if need_help or query == "": + print self.longHelp() + sys.exit(-1) + + return (query, opts) + + def perform(self, args): + (query, opts) = self.parseArgs(args) + + (cat, name, ver, rev) = gentoolkit.split_package_name(query) + + if rev == "r0": rev = ".*" + if name == "": name = ".*" + if ver == "": ver = ".*" + if cat == "": cat = ".*" + + package_finder = None + + if opts["includeInstalled"] and (opts["includePortTree"] or opts["includeOverlayTree"]): + package_finder = gentoolkit.find_all_packages + elif opts["includeInstalled"]: + package_finder = gentoolkit.find_all_installed_packages + elif opts["includePortTree"] or opts["includeOverlayTree"]: + package_finder = gentoolkit.find_all_uninstalled_packages + + if not package_finder: + print red("!!! You must specify one of ") + yellow("-i") + red(", ") + yellow("-p") + red(" or ") + yellow("-o") + sys.exit(2) + + rx = re.compile(cat + "/" + name) + filter_fn = lambda x: rx.search(x) + + if Config["verbosityLevel"] >= 3: + scat = "'" + cat + "'" + if cat == ".*": + scat = "all categories" + sname = "package '" + name + "'" + if name == ".*": + sname = "all packages" + print "Searching for " + sname + " in " + scat + " among:" + if opts["includeInstalled"]: + print turquoise(" *") + " installed packages" + if opts["includePortTree"]: + print turquoise(" *") + " Portage tree (" + gentoolkit.settings["PORTDIR"] + ")" + if opts["includeOverlayTree"]: + print turquoise(" *") + " overlay tree (" + gentoolkit.settings["PORTDIR_OVERLAY"] + ")" + + matches = package_finder(filter_fn) + + rx = re.compile(cat + "/" + name + "-" + ver + "(-" + rev + ")?") + pfxmodes = [ "[---]", "[I--]", "[-P-]", "[--O]" ] + for pkg in matches: + status = 0 + if pkg.is_installed(): + status = 1 + elif pkg.is_overlay(): + status = 3 + else: + status = 2 + + if (status == 1 and opts["includeInstalled"]) or \ + (status == 2 and opts["includePortTree"]) or \ + (status == 3 and opts["includeOverlay"]): + if rx.search(pkg.get_cpv()): + print pfxmodes[status] + " " + pkg.get_cpv() + + def shortHelp(self): + return yellow(" ") + teal("pkgspec") + " - list all packages matching " + teal("pkgspec") + def longHelp(self): + return "List all packages matching a query pattern" + \ + "\n" + \ + "Syntax:\n" + \ + " " + green("list") + yellow(" ") + teal("pkgspec") + \ + "\n" + \ + yellow("") + " is either of: \n" + \ + " " + yellow("-i, --installed") + " - search installed packages (default)\n" + \ + " " + yellow("-I, --exclude-installed") + " - do not search installed packages\n" + \ + " " + yellow("-p, --portage-tree") + " - also search in portage tree (" + gentoolkit.settings["PORTDIR"] + ")\n" + \ + " " + yellow("-o, --overlay-tree") + " - also search in overlay tree (" + gentoolkit.settings["PORTDIR_OVERLAY"] + ")\n" + + +Known_commands = { + "list": CmdListPackages(), + "files": CmdListFiles(), + "belongs": CmdListBelongs(), + "depends": CmdListDepends(), + "uses": CmdDisplayUSEs(), + "depgraph": CmdDisplayDepGraph(), + "changes": CmdDisplayChanges(), + "size": CmdDisplaySize(), + "check": CmdCheckIntegrity(), + "stats": CmdDisplayStatistics(), + "glsa": CmdListGLSAs(), + "which": CmdWhich() + } + +Config = { + # Query will include packages installed on the system + "installedPackages": 1, + # Query will include packages available for installation + "uninstalledPackages": 0, + # Query will include overlay packages (iff uninstalledPackages==1) + "overlayPackages": 1, + # Query will include masked packages (iff uninstalledPackages==1) + "maskedPackages": 0, + # Query will only consider packages in the following categories, empty means all. + "categoryFilter": [], + # Enable color output (-1 = use Portage setting, 0 = force off, 1 = force on) + "color": -1, + # Level of detail on the output + "verbosityLevel": 3, + # Query will display info for multiple SLOTed versions + "considerDuplicates": 1 +} + +def printVersion(): + print __productname__ + "(" + __version__ + ") - " + \ + __description__ + print "Author(s): " + __author__ + +def printUsage(): + print white("Usage: ") + turquoise(__productname__) + yellow(" ") + green("command") + yellow(" ") + print "where " + yellow("") + " is one of" + print yellow(" -q, --quiet") + " - minimal output" + print yellow(" -C, --nocolor") + " - turn off colours" + print yellow(" -h, --help") + " - this help screen" + print yellow(" -V, --version") + " - display version info" + + print "where " + green("command") + " is one of" + for x in Known_commands.keys(): + print " " + green(x) + " " + Known_commands[x].shortHelp() + +def parseArgs(args): + + command = None + local_opts = [] + + for i in xrange(len(args)): + x = args[i] + if 0: + pass + elif x in ["-h","--help"]: + printUsage() + sys.exit(0) + elif x in ["-V","--version"]: + printVersion() + sys.exit(0) + elif x in ["-C","--nocolor"]: + Config.color = 0 + elif x in ["-q","--quiet"]: + Config["verbosityLevel"] = 0 + elif x in Known_commands.keys(): + command = Known_commands[x] + local_opts = args[i+1:] + break + + # Set up colour output correctly + if (Config["color"] == -1 and \ + ((not sys.stdout.isatty()) or \ + (gentoolkit.settings["NOCOLOR"] in ["yes","true"]))) \ + or \ + Config["color"] == 0: + nocolor() + + return (command, local_opts) + +if __name__ == "__main__": + (cmd, local_opts) = parseArgs(sys.argv[1:]) + if cmd: + cmd.perform(local_opts) + diff --git a/trunk/src/equery/equery.1 b/trunk/src/equery/equery.1 new file mode 100644 index 0000000..6e921af --- /dev/null +++ b/trunk/src/equery/equery.1 @@ -0,0 +1,12 @@ +.TH equery "1" "Jan 2004" "gentoolkit" +.SH NAME +equery \- Gentoo: Package Query Tool +.SH SYNOPSIS +.B equery +.SH BUGS +This tool does not yet have a man page. Feel free to submit a bug about it to +http://bugs.gentoo.org +.SH AUTHORS +This informative man page was written by Karl Trygve Kalleberg +. + diff --git a/trunk/src/etcat/ChangeLog b/trunk/src/etcat/ChangeLog index 6e3e3f7..57d90f3 100644 --- a/trunk/src/etcat/ChangeLog +++ b/trunk/src/etcat/ChangeLog @@ -1,3 +1,9 @@ + +2004-01-07 Karl Trygve Kalleberg + * Added man page from app-portage/gentoolkit + * Added Makefile + * Added sys.path workaround for Portage >=2.0.50 + * etcat-0.2.0 (06 May 2003) 06 May 2003; Alastair Tse Trying to add a dependency graph feature. kind of works with diff --git a/trunk/src/etcat/etcat.1 b/trunk/src/etcat/etcat.1 index b8f3328..6704f3b 100644 --- a/trunk/src/etcat/etcat.1 +++ b/trunk/src/etcat/etcat.1 @@ -1,7 +1,7 @@ .TH "etcat" "1" "0.1.4" "Alastair Tse " "Gentoo Administration" .SH "NAME" .LP -etcat \- Gentoo Portage Information Extractor +etcat \- Gentoo: Portage Information Extractor .SH "SYNTAX" .LP etcat [\fIoption\fP|command] <\fIquery|package\fP> diff --git a/trunk/src/euse/ChangeLog b/trunk/src/euse/ChangeLog index 1aa2a6b..cb50dbb 100644 --- a/trunk/src/euse/ChangeLog +++ b/trunk/src/euse/ChangeLog @@ -1,5 +1,9 @@ -*euse-0.1.0 (09 May 2003) - 09 May 2003; Arun Bhanu - Initial commit to gentoolkit. +2004-01-07 Karl Trygve Kalleberg + * Added Makefile + * Updated from app-portage/gentoolkit + * Reformatted ChangeLog + +2003-05-09 Arun Bhanu + * Initial commit to gentoolkit. diff --git a/trunk/src/gentool/AUTHORS b/trunk/src/gentool/AUTHORS deleted file mode 100644 index 9935ef7..0000000 --- a/trunk/src/gentool/AUTHORS +++ /dev/null @@ -1,3 +0,0 @@ -Karl Trygve Kalleberg - * Initial version - diff --git a/trunk/src/gentool/ChangeLog b/trunk/src/gentool/ChangeLog deleted file mode 100644 index 94dfaaf..0000000 --- a/trunk/src/gentool/ChangeLog +++ /dev/null @@ -1,17 +0,0 @@ -2003-12-31 Karl Trygve Kalleberg - * Added which command - * Added check command (not finished) - -2003-12-12 Karl Trygve Kalleberg - * Added size command - * Added depgraph command - -2003-12-11 Karl Trygve Kalleberg - * Added list command - * Added uses command - -2003-10-05 Karl Trygve Kalleberg - * Added files command - * Added belongs command - - diff --git a/trunk/src/gentool/Makefile b/trunk/src/gentool/Makefile deleted file mode 100644 index 77798c6..0000000 --- a/trunk/src/gentool/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2003 Karl Trygve Kalleberg -# Copyright 2003 Gentoo Technologies, Inc. -# Distributed under the terms of the GNU General Public License v2 -# -# $Header$ - -include ../../makedefs.mak - -all: - echo "YADDLETHORPE (vb.) (Of offended pooves.) To exit huffily from a boutique." - -dist: - mkdir -p ../../$(distdir)/src/gentool/ - cp {Makefile,AUTHORS,README,TODO,ChangeLog,gentool,gentool.1} ../../$(distdir)/src/gentool/ - -install: - install -m 0755 gentool $(bindir)/ - install -d $(docdir)/gentool - install -m 0644 {README,AUTHORS} $(docdir)/gentool/ - install -m 0644 gentool.1 $(mandir)/ diff --git a/trunk/src/gentool/README b/trunk/src/gentool/README deleted file mode 100644 index e69de29..0000000 diff --git a/trunk/src/gentool/TODO b/trunk/src/gentool/TODO deleted file mode 100644 index e69de29..0000000 diff --git a/trunk/src/gentool/gentool b/trunk/src/gentool/gentool deleted file mode 100755 index 34128af..0000000 --- a/trunk/src/gentool/gentool +++ /dev/null @@ -1,897 +0,0 @@ -#! /usr/bin/env python2.2 -# -# Copyright 2003 Karl Trygve Kalleberg -# Copyright 2003 Gentoo Technologies, Inc. -# Distributed under the terms of the GNU General Public License v2 -# -# $Header$ -# Author: Karl Trygve Kalleberg - -__author__ = "Karl Trygve Kalleberg" -__email__ = "karltk@gentoo.org" -__version__ = "0.1.0" -__productname__ = "gentool" -__description__ = "Gentoo Package Query Tool" - -import re -import sys -import time -import string -import gentoolkit -from output import * - - -# Auxiliary functions - -def fileAsStr(name, fdesc, showType=0, showMD5=0, showTimestamp=0): - - type = ""; fname = ""; stamp = ""; md5sum = "" - - if fdesc[0] == 'obj': - type = "file" - fname = name - stamp = timestampAsStr(int(fdesc[1])) - md5sum = fdesc[2] - elif fdesc[0] == "dir": - type = "dir" - fname = white(name) - elif fdesc[0] == "sym": - type = "symlink" - stamp = timestampAsStr(int(fdesc[1].replace(")",""))) - tgt = fdesc[2].split()[0] - fname = turquoise(name + " -> " + tgt) - else: - raise "Unknown type: " + fdesc[0] - - s = "" - if showType: - s += "%6s " % type - s += fname - if showTimestamp: - s += stamp + " " - if showMD5: - s += md5sum + " " - return s - -def timestampAsStr(timestamp): - return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)) - - -class Command: - def __init__(self): - pass - def shortHelp(self): - return "short help description" - def longHelp(self): - return "help for syntax and options" - def perform(self, args): - pass - def parseArgs(self, args): - pass - - -class CmdListFiles(Command): - """List files owned by a particular package""" - def __init__(self): - self.default_options = { - "showType": 0, - "showTimestamp": 0, - "showMD5": 0 - } - - def parseArgs(self,args): - query = "" - need_help = 0 - opts = self.default_options - for x in args: - if x in ["-h", "--help"]: - need_help = 1 - elif x in ["--md5sum"]: - opts["showMD5"] = 1 - elif x in ["--timestamp"]: - opts["showTimestamp"] = 1 - elif x in ["--type"]: - opts["showType"] = 1 - else: - query = x - - if need_help or query == "": - print self.longHelp() - sys.exit(-1) - - return (query, opts) - - def perform(self, args): - - (query, opts) = self.parseArgs(args) - - if Config["verbosityLevel"] >= 3: - print "Searching for packages matching '" + query + "'..." - - pkgs = gentoolkit.find_packages(query) - for x in pkgs: - - if not x.is_installed(): - continue - - if Config["verbosityLevel"] >= 1: - print "Contents of " + x.get_cpv() + ":" - - cnt = x.get_contents() - - for name in cnt: - print fileAsStr(name, - cnt[name], - showType=opts["showType"], - showTimestamp=opts["showTimestamp"], - showMD5=opts["showMD5"]) - - - def longHelp(self): - return "List files owned by a particular package\n" + \ - "\n" + \ - "Syntax:\n" + \ - " " + green("files") + yellow(" packagename<-version>") + "\n" + \ - "\n" + \ - "Note: category and version parts are optional. \n" + \ - "\n" + \ - yellow("") + " is either of: \n" + \ - " " + yellow("--timestamp") + " - append timestamp\n" + \ - " " + yellow("--md5sum") + " - append md5sum\n" + \ - " " + yellow("--type") + " - prepend file type" - def shortHelp(self): - return yellow(" ") + teal("pkgspec") + " - list files owned by " + teal("pkgspec") - - -class CmdListBelongs(Command): - """List all packages owning a particular file""" - def __init__(self): - self.default_opts = { - "category": "*", - "earlyOut": 0 - } - - def parseArgs(self, args): - - query = "" - need_help = 0 - opts = self.default_opts - skip = 0 - - for i in xrange(len(args)): - - if skip: - skip -= 1 - continue - x = args[i] - - if x in ["-h","--help"]: - need_help = 1 - break - elif x in ["-c", "--category"]: - opts["category"] = args[i+1] - skip = 1 - elif x in ["-e", "--earlyout"]: - opts["earlyOut"] = 1 - else: - query = x - - if need_help or query == "": - print self.longHelp() - sys.exit(-1) - - return (query, opts) - - def perform(self, args): - (query, opts) = self.parseArgs(args) - - cat = opts["category"] - filter_fn = None - if cat != "*": - filter_fn = lambda x: x.find(cat+"/")==0 - - if Config["verbosityLevel"] >= 3: - print "Searching for file '" + query + "' in " + cat + "..." - - matches = gentoolkit.find_all_installed_packages(filter_fn) - rx = re.compile(query) - - found = 0 - for pkg in matches: - cnt = pkg.get_contents() - for file in cnt.keys(): - if rx.search(file): - print pkg.get_cpv() + " (" + fileAsStr(file, cnt[file]) + ")" - if opts["earlyOut"]: - found = 1 - break - if found: - break - - def shortHelp(self): - return yellow(" ") + teal("file") + " - list all packages owning " + teal("file") - def longHelp(self): - return "List all packages owning a particular file" + \ - "\n" + \ - "\n" + \ - turquoise("Note: ") + "Normally, only one package will own a file. If multiple packages own the same file, it usually consitutes a problem, and should be reported.\n" + \ - "\n" + \ - "Syntax:\n" + \ - " " + green("belongs") + yellow(" ") + teal("filename") + \ - "\n" + \ - yellow("") + " is either of: \n" + \ - " " + yellow("-c, --category cat") + " - only search in category " + yellow("cat") + "\n" + \ - " " + yellow("-e, --earlyout") + " - stop when first match found\n" - -class CmdDisplayUSEs(Command): - """Advanced report of a package's USE flags""" - def __init__(self): - self.default_opts = { - } - def parseArgs(self, args): - - query = "" - need_help = 0 - opts = self.default_opts - skip = 0 - - for i in xrange(len(args)): - - if skip: - skip -= 1 - continue - x = args[i] - - if x in ["-h","--help"]: - need_help = 1 - break - else: - query = x - - if need_help or query == "": - print self.longHelp() - sys.exit(-1) - - return (query, opts) - - def perform(self, args): - - (query, opts) = self.parseArgs(args) - - matches = gentoolkit.find_packages(query) - - useflags = gentoolkit.settings["USE"].split() - usedesc = {} - uselocaldesc = {} - - # Load global USE flag descriptions - try: - fd = open(gentoolkit.settings["PORTDIR"]+"/profiles/use.desc") - usedesc = {} - for line in fd.readlines(): - if line[0] == "#": - continue - fields = line.split(" - ") - if len(fields) == 2: - usedesc[fields[0].strip()] = fields[1].strip() - except IOError: - if Config["verbosityLevel"] >= 5: - print "Warning: Could not load USE flag descriptions from " + gentoolkit.settings["PORTDIR"] + "/profiles/use.desc" - - # Load local USE flag descriptions - try: - fd = open(gentoolkit.settings["PORTDIR"]+"/profiles/use.local.desc") - for line in fd.readlines(): - if line[0] == "#": - continue - fields = line.split(" - ") - if len(fields) == 2: - catpkguse = re.search("([a-z]+-[a-z]+/.*):(.*)", fields[0]) - if catpkguse: - if not uselocaldesc.has_key(catpkguse.group(1).strip()): - uselocaldesc[catpkguse.group(1).strip()] = {catpkguse.group(2).strip() : fields[1].strip()} - else: - uselocaldesc[catpkguse.group(1).strip()][catpkguse.group(2).strip()] = fields[1].strip() - except IOError: - if Config["verbosityLevel"] >= 5: - print "Warning: Could not load USE flag descriptions from " + gentoolkit.settings["PORTDIR"] + "/profiles/use.desc" - - print "[ Colour Code : " + green("set") + " " + red("unset") + " ]" - print "[ Legend : (U) Col 1 - Current USE flags ]" - print "[ : (I) Col 2 - Installed With USE flags ]" - - # Iterate through matches, printing a report for each package - for p in matches: - if not p.is_installed(): - continue - - bestver = p.get_cpv() - iuse = p.get_env_var("IUSE") - - if iuse: usevar = iuse.split() - else: usevar = [] - - inuse = [] - used = p.get_use_vars().split() - - # store (inuse, inused, flag, desc) - output = [] - - for u in usevar: - inuse = 0 - inused = 0 - try: - desc = usedesc[u] - except KeyError: - try: - desc = uselocaldesc[p][u] - except KeyError: - desc = "" - - if u in useflags: inuse = 1 - if u in used: inused = 1 - - output.append((inuse, inused, u, desc)) - - # pretty print - if output: - print - print white(" U I ") + "[ Found these USE variables in : " + white(bestver) + " ]" - maxflag_len = 0 - for inuse, inused, u, desc in output: - if len(u) > maxflag_len: - maxflag_len = len(u) - - for inuse, inused, u, desc in output: - flag = ["-","+"] - colour = [red, green] - if inuse != inused: - print yellow(" %s %s" % (flag[inuse], flag[inused])), - else: - print " %s %s" % (flag[inuse], flag[inused]), - - print colour[inuse](u.ljust(maxflag_len)), - - # print description - if desc: - print ":", desc - else: - print ": unknown" - else: - print "[ No USE flags found for :", white(p.get_cpv()), "]" - def shortHelp(self): - return yellow(" ") + teal("pkgspec") + " - display USE flags for " + teal("pkgspec") - def longHelp(self): - return "Display USE flags for a given package\n" + \ - "\n" + \ - "Syntax:\n" + \ - " " + green("uses") + yellow(" ") + teal("pkgspec") + \ - "\n" + \ - yellow("") + " is either of: \n" - - -class CmdDisplayDepGraph(Command): - """Display tree graph of deps for pkgQuery""" - - def __init__(self): - self.default_opts = { - "displayUSEFlags": 1, - "fancyFormatting": 1 - } - - def parseArgs(self, args): - - query = "" - need_help = 0 - opts = self.default_opts - skip = 0 - - for i in xrange(len(args)): - - if skip: - skip -= 1 - continue - x = args[i] - - if x in ["-h","--help"]: - need_help = 1 - break - elif x in ["-U","--no-useflags"]: - opts["displayUSEFlags"] = 0 - elif x in ["-l","--linear"]: - opts["fancyFormatting"] = 0 - else: - query = x - - if need_help or query == "": - print self.longHelp() - sys.exit(-1) - - return (query, opts) - - def perform(self, args): - (query, opts) = self.parseArgs(args) - - matches = gentoolkit.find_packages(query) - - for pkg in matches: - - if Config["verbosityLevel"] >= 3: - print "Displaying dependencies for " + pkg.get_cpv() + "\n" - - if not pkg.is_installed(): - continue - self._graph(pkg, opts) - - def _graph(self, pkg, opts, level=0,pkgtbl=[],suffix=""): - - cpv=pkg.get_cpv() - - pfx = "" - if opts["fancyFormatting"]: - pfx = level*" " + "`-- " - print pfx + cpv + suffix - - pkgtbl.append(cpv) - - for x in pkg.get_runtime_deps(): - suffix = "" - cpv = x[2] - pkg = gentoolkit.find_best_match(x[0] + cpv) - if not pkg: - continue - if pkg.get_cpv() in pkgtbl: - continue - if cpv.find("virtual")==0: - suffix += " (" + cpv + ")" - if len(x[1]) and opts["displayUSEFlags"]: - suffix += " [ " + string.join(x[1]) + " ]" - pkgtbl = self._graph(pkg, opts, level+1, pkgtbl, suffix) - return pkgtbl - - def shortHelp(self): - return yellow(" ") + teal("pkgspec") + " - display a dependency tree for " + teal("pkgspec") - def longHelp(self): - return "Display a dependency tree for a given package\n" + \ - "\n" + \ - "Syntax:\n" + \ - " " + green("depgraph") + yellow(" ") + teal("pkgspec") + \ - "\n" + \ - yellow("") + " is either of: \n" + \ - " " + yellow("-U, --no-useflags") + " - do not show USE flags\n" + \ - " " + yellow("-l, --linear") + " - do not use fancy formatting" - -class CmdDisplaySize(Command): - """Display disk size consumed by a package""" - def __init__(self): - self.default_opts = { - "reportSizeInBytes": 0 - } - - def parseArgs(self, args): - - query = "" - need_help = 0 - opts = self.default_opts - skip = 0 - - for i in xrange(len(args)): - - if skip: - skip -= 1 - continue - x = args[i] - - if x in ["-h","--help"]: - need_help = 1 - break - elif x in ["-b","--bytes"]: - opts["reportSizeInBytes"] = 1 - else: - query = x - - if need_help or query == "": - print self.longHelp() - sys.exit(-1) - - return (query, opts) - - def perform(self, args): - (query, opts) = self.parseArgs(args) - - matches = gentoolkit.find_packages(query) - - for pkg in matches: - if not pkg.is_installed(): - continue - - (size, files, uncounted) = pkg.size() - - print turquoise("*") + " " + white(pkg.get_cpv()) - print string.rjust(" Total Files : ",25) + str(files) - - if uncounted: - print string.rjust(" Inaccessible Files : ",25) + str(uncounted) - - sz = "%.2f KiB" % (size/1024.0) - if opts["reportSizeInBytes"]: - sz = str(size) + " bytes" - - print string.rjust("Total Size : ",25) + sz - - - def shortHelp(self): - return yellow(" ") + teal("pkgspec") + " - print size of files contained in package " + teal("pkgspec") - def longHelp(self): - return "Print size total size of files contained in a given package" + \ - "\n" + \ - "Syntax:\n" + \ - " " + green("size") + yellow(" ") + teal("pkgspec") + \ - "\n" + \ - yellow("") + " is either of: \n" + \ - " " + yellow("-b, --bytes") + " - report size in bytes\n" - -class CmdDisplayChanges(Command): - """Display changes for pkgQuery""" - pass - -class CheckException: - def __init__(self, s): - self.s = s - -class CmdCheckIntegrity(Command): - """Check timestamps and md5sums for files owned by pkgspec""" - def __init__(self): - self.default_opts = { - "showSummary" : 1, - "showGoodFiles" : 0, - "showBadFiles" : 1, - "checkTimestamp" : 1, - "checkMD5sum": 1 - } - - def parseArgs(self, args): - - query = "" - need_help = 0 - opts = self.default_opts - skip = 0 - - for i in xrange(len(args)): - if skip: - skip -= 1 - continue - x = args[i] - - if x in ["-h","--help"]: - need_help = 1 - break - else: - query = x - - if need_help or query == "": - print self.longHelp() - sys.exit(-1) - - return (query, opts) - - def checkMD5sum(self, file): - return 1 - - def perform(self, args): - (query, opts) = self.parseArgs(args) - - matches = gentoolkit.find_packages(query) - - for pkg in matches: - if not pkg.is_installed(): - continue - files = pkg.get_contents() - for file in files.keys(): - type = files[file][0] - try: - st = os.lstat(file) - if type == "dir": - if not os.path.isdir(file): - raise CheckException(file + " exists, but is not a directory") - elif type == "obj": - mtime = files[file][1] - if opts["checkTimestamp"]: - if st.st_mtime != int(mtime): - raise CheckException(file + (" has wrong mtime (is %d, should be %s)" % (st.st_mtime, mtime))) - if opts["checkMD5sum"]: - if not self.checkMD5sum(file): - raise CheckException(file + " has incorrect md5sum") - elif type == "sym": - # FIXME: nastry strippery; portage should have this fixed! - t = files[file][2] - i = t.find("(") - target = t[0:i].strip() - if not os.path.islink(file): - raise CheckException(file + " exists, but is not a symlink") - tgt = os.readlink(file) - if tgt != target: - raise CheckException(file + " does not point to " + target) - - else: - print file - print files[file] - print type - raise "Unknown type" - except CheckException, (e): - print e.s - except OSError: - print file + " does not exist" - - def shortHelp(self): - return teal("pkgspec") + " - check package's files against recorded MD5 sums and timestamps" - def longHelp(self): - return "Check package's files against recorded MD5 sums and timestamps" - -class CmdDisplayStatistics(Command): - """Display statistics about installed and uninstalled packages""" - pass - -class CmdWhich(Command): - """Display the filename of the ebuild for a given package - that would be used by Portage with the current configuration.""" - def __init__(self): - self.default_opts = {} - - def parseArgs(self, args): - - query = "" - need_help = 0 - opts = self.default_opts - skip = 0 - - for i in xrange(len(args)): - - if skip: - skip -= 1 - continue - x = args[i] - - if x in ["-h","--help"]: - need_help = 1 - break - else: - query = x - - if need_help or query == "": - print self.longHelp() - sys.exit(-1) - - return (query, opts) - - def perform(self, args): - (query, opts) = self.parseArgs(args) - - matches = gentoolkit.find_packages(query) - - for pkg in matches: - print os.path.normpath(pkg.get_ebuild_path()) - - def shortHelp(self): - return teal("pkgspec") + " - print full path to ebuild for package " + teal("pkgspec") - def longHelp(self): - return "Print full path to ebuild for a given package" - -class CmdListGLSAs(Command): - """List outstanding GLSAs.""" - pass - -class CmdListDepends(Command): - """List all packages directly or indirectly depending on pkgQuery""" - pass - -class CmdListPackages(Command): - """List packages satisfying pkgQuery""" - def __init__(self): - self.default_opts = { - "category": "*", - "includeInstalled": 1, - "includePortTree": 0, - "includeOverlayTree": 0, - "regex": 0 - } - - def parseArgs(self, args): - - query = "" - need_help = 0 - opts = self.default_opts - skip = 0 - - for i in xrange(len(args)): - - if skip: - skip -= 1 - continue - x = args[i] - - if x in ["-h","--help"]: - need_help = 1 - break - elif x in ["-i", "--installed"]: - opts["includeInstalled"] = 1 - elif x in ["-I", "--exclude-installed"]: - opts["includeInstalled"] = 0 - elif x in ["-p", "--portage-tree"]: - opts["includePortTree"] = 1 - elif x in ["-o", "--overlay-tree"]: - opts["includeOverlayTree"] = 1 - else: - query = x - - if need_help or query == "": - print self.longHelp() - sys.exit(-1) - - return (query, opts) - - def perform(self, args): - (query, opts) = self.parseArgs(args) - - (cat, name, ver, rev) = gentoolkit.split_package_name(query) - - if rev == "r0": rev = ".*" - if name == "": name = ".*" - if ver == "": ver = ".*" - if cat == "": cat = ".*" - - package_finder = None - - if opts["includeInstalled"] and (opts["includePortTree"] or opts["includeOverlayTree"]): - package_finder = gentoolkit.find_all_packages - elif opts["includeInstalled"]: - package_finder = gentoolkit.find_all_installed_packages - elif opts["includePortTree"] or opts["includeOverlayTree"]: - package_finder = gentoolkit.find_all_uninstalled_packages - - if not package_finder: - print red("!!! You must specify one of ") + yellow("-i") + red(", ") + yellow("-p") + red(" or ") + yellow("-o") - sys.exit(2) - - rx = re.compile(cat + "/" + name) - filter_fn = lambda x: rx.search(x) - - if Config["verbosityLevel"] >= 3: - scat = "'" + cat + "'" - if cat == ".*": - scat = "all categories" - sname = "package '" + name + "'" - if name == ".*": - sname = "all packages" - print "Searching for " + sname + " in " + scat + " among:" - if opts["includeInstalled"]: - print turquoise(" *") + " installed packages" - if opts["includePortTree"]: - print turquoise(" *") + " Portage tree (" + gentoolkit.settings["PORTDIR"] + ")" - if opts["includeOverlayTree"]: - print turquoise(" *") + " overlay tree (" + gentoolkit.settings["PORTDIR_OVERLAY"] + ")" - - matches = package_finder(filter_fn) - - rx = re.compile(cat + "/" + name + "-" + ver + "(-" + rev + ")?") - pfxmodes = [ "[---]", "[I--]", "[-P-]", "[--O]" ] - for pkg in matches: - status = 0 - if pkg.is_installed(): - status = 1 - elif pkg.is_overlay(): - status = 3 - else: - status = 2 - - if (status == 1 and opts["includeInstalled"]) or \ - (status == 2 and opts["includePortTree"]) or \ - (status == 3 and opts["includeOverlay"]): - if rx.search(pkg.get_cpv()): - print pfxmodes[status] + " " + pkg.get_cpv() - - def shortHelp(self): - return yellow(" ") + teal("pkgspec") + " - list all packages matching " + teal("pkgspec") - def longHelp(self): - return "List all packages matching a query pattern" + \ - "\n" + \ - "Syntax:\n" + \ - " " + green("list") + yellow(" ") + teal("pkgspec") + \ - "\n" + \ - yellow("") + " is either of: \n" + \ - " " + yellow("-i, --installed") + " - search installed packages (default)\n" + \ - " " + yellow("-I, --exclude-installed") + " - do not search installed packages\n" + \ - " " + yellow("-p, --portage-tree") + " - also search in portage tree (" + gentoolkit.settings["PORTDIR"] + ")\n" + \ - " " + yellow("-o, --overlay-tree") + " - also search in overlay tree (" + gentoolkit.settings["PORTDIR_OVERLAY"] + ")\n" - - -Known_commands = { - "list": CmdListPackages(), - "files": CmdListFiles(), - "belongs": CmdListBelongs(), - "depends": CmdListDepends(), - "uses": CmdDisplayUSEs(), - "depgraph": CmdDisplayDepGraph(), - "changes": CmdDisplayChanges(), - "size": CmdDisplaySize(), - "check": CmdCheckIntegrity(), - "stats": CmdDisplayStatistics(), - "glsa": CmdListGLSAs(), - "which": CmdWhich() - } - -Config = { - # Query will include packages installed on the system - "installedPackages": 1, - # Query will include packages available for installation - "uninstalledPackages": 0, - # Query will include overlay packages (iff uninstalledPackages==1) - "overlayPackages": 1, - # Query will include masked packages (iff uninstalledPackages==1) - "maskedPackages": 0, - # Query will only consider packages in the following categories, empty means all. - "categoryFilter": [], - # Enable color output (-1 = use Portage setting, 0 = force off, 1 = force on) - "color": -1, - # Level of detail on the output - "verbosityLevel": 3, - # Query will display info for multiple SLOTed versions - "considerDuplicates": 1 -} - -def printVersion(): - print __productname__ + "(" + __version__ + ") - " + \ - __description__ - print "Author(s): " + __author__ - -def printUsage(): - print white("Usage: ") + turquoise("gentool") + yellow(" ") + green("command") + yellow(" ") - print "where " + yellow("") + " is one of" - print yellow(" -q, --quiet") + " - minimal output" - print yellow(" -C, --nocolor") + " - turn off colours" - print yellow(" -h, --help") + " - this help screen" - print yellow(" -V, --version") + " - display version info" - - print "where " + green("command") + " is one of" - for x in Known_commands.keys(): - print " " + green(x) + " " + Known_commands[x].shortHelp() - -def parseArgs(args): - - command = None - local_opts = [] - - for i in xrange(len(args)): - x = args[i] - if 0: - pass - elif x in ["-h","--help"]: - printUsage() - sys.exit(0) - elif x in ["-V","--version"]: - printVersion() - sys.exit(0) - elif x in ["-C","--nocolor"]: - Config.color = 0 - elif x in ["-q","--quiet"]: - Config["verbosityLevel"] = 0 - elif x in Known_commands.keys(): - command = Known_commands[x] - local_opts = args[i+1:] - break - - # Set up colour output correctly - if (Config["color"] == -1 and \ - ((not sys.stdout.isatty()) or \ - (gentoolkit.settings["NOCOLOR"] in ["yes","true"]))) \ - or \ - Config["color"] == 0: - nocolor() - - return (command, local_opts) - -if __name__ == "__main__": - (cmd, local_opts) = parseArgs(sys.argv[1:]) - if cmd: - cmd.perform(local_opts) - diff --git a/trunk/src/gentool/gentool-bump-revision b/trunk/src/gentool/gentool-bump-revision deleted file mode 100755 index 234b83c..0000000 --- a/trunk/src/gentool/gentool-bump-revision +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/sh -# Copyright 2002-2003 Gentoo Technologies, Inc. -# Distributed under the terms of the GNU General Public License v2 -# $Header$ -# Author: Karl Trygve Kalleberg - -if [ ! -f $HOME/.gentoo/gentool-env ] ; then - echo "You must make a $HOME/.gentoo/gentool-env file that contains" - echo "AUTHORNAME=\"Your name\"" - echo "AUTHOREMAIL=\"Your @gentoo.org mail address\"" -fi - -. $HOME/.gentoo/gentool-env - -dn="`dirname $1`" -bn="`basename $1`" -ebuild=`echo $bn | sed "s/\.ebuild//"` - -ver=`echo $ebuild | sed "s/\(.*\)-\([0-9].*\)/\2/"` -name=`echo $ebuild | sed "s/\(.*\)-\([0-9].*\)/\1/"` -rev=`echo $ver | grep "\-r[0-9]*" | sed "s/.*-r\([0-9]*\)/\1/"` -basever=`echo $ver | sed "s/-r[0-9]*//"` - -oldver=$ebuild -newver="" -if [ -z "$rev" ] ; then - newver=${ebuild}-r1 -else - newrev=$[rev + 1] - newver=${name}-${basever}-r${newrev} -fi - -echo "# Directory : $dn" -echo "# Old version : $oldver" -echo "# New version : $newver" -echo - -cd ${dn} - -echo "Updating revisions for ebuilds digests" -mv ${oldver}.ebuild ${newver}.ebuild -mv files/digest-${oldver} files/digest-${newver} - -#echo "Removing old revisions from CVS" -#cvs remove -f ${oldver}.ebuild -#cvs remove -f files/digest-${oldver} - -echo "Adding new revisions to CVS" -cvs add ${newver}.ebuild -cvs add files/digest-${newver} - -if [ ! -f ChangeLog ] ; then - echo "!!! Cannot fix ChangeLog, does not exist" > /dev/stderr - exit -1 -fi - -echo "Adding new entry in ChangeLog" - -lns=`cat ChangeLog | wc -l | tr -d ' '` -mv ChangeLog ChangeLog.orig -(head -n 3 ChangeLog.orig ; - echo "" - echo "*$newver (`date +\"%d %b %Y\"`)" ; - echo "" ; - echo " `date +\"%d %b %Y\"`; $AUTHORNAME <$AUTHOREMAIL> ${newver}.ebuild files/digest-${newver}:" ; - echo "" ; - echo " # INSERT COMMENT HERE" ; - echo "" ; - echo " Removed ${oldver}.ebuild files/digest-${oldver}" ; - echo "" ; - tail -n $[lns-4] ChangeLog.orig -) > ChangeLog diff --git a/trunk/src/gentool/gentool-bump-revision.1 b/trunk/src/gentool/gentool-bump-revision.1 deleted file mode 100644 index b7efc47..0000000 --- a/trunk/src/gentool/gentool-bump-revision.1 +++ /dev/null @@ -1,20 +0,0 @@ -.TH gentool-bump-revision "1" "Nov 2002" "gentoolkit" -.SH NAME -gentool-bump-revision \- Bumps the revision number of a given package -.SH SYNOPSIS -.B gentool-bump-revision -\fIebuild\fR -.SH DESCRIPTION -The \fBgentool-bump-revision\fR utility bumps the revision of an existing -ebuild in the Portage tree. It does this by copying the specified ebuild -file to a new filename with an increased revision number. It takes care -of the digest file, adding both to CVS, and it also adds an entry in the -ChangeLog for you to fill in. After the revision bump, should always make -certain any auxiliary files like scripts, etc, are installed properly. -.SH AUTHOR -Karl Trygve Kalleberg , 2002 -.SH SEE ALSO -change(1) -.TP -See \fI/usr/share/doc/gentoolkit-/\fR for documentation on other gentoolkit utilities. - diff --git a/trunk/src/gentool/gentool-package-count b/trunk/src/gentool/gentool-package-count deleted file mode 100755 index f7e02e4..0000000 --- a/trunk/src/gentool/gentool-package-count +++ /dev/null @@ -1,9 +0,0 @@ -#! /bin/sh - -pcnt=`find /usr/portage/ -type f -name "*.ebuild" | sed "s/-[0-9].*//" | sort | uniq | wc -l` -numebuilds=`find /usr/portage/ -type f -name "*.ebuild" | wc -l` -numcat=`find /usr/portage/ -type d -name "*-*" -maxdepth 1 | wc -l` - -echo "Number of categories : $numcat" -echo "Number of ebuilds : $numebuilds" -echo "Unique packages : $pcnt" diff --git a/trunk/src/gentool/gentool-package-count.1 b/trunk/src/gentool/gentool-package-count.1 deleted file mode 100644 index ad27479..0000000 --- a/trunk/src/gentool/gentool-package-count.1 +++ /dev/null @@ -1,17 +0,0 @@ -.TH gentool-package-count "1" "Nov 2002" "gentoolkit" -.SH NAME -gentool-package-count\- Counts the number of packages available in the tree. -.SH SYNOPSIS -.B gentool-package-revision -.SH DESCRIPTION -The \fBgentool-package-count\fR utility counts the number of packages -available for installation in your local Portage tree. It will inform of -total package count, total category count, and total unique packages. It -is completely useless. -.SH AUTHOR -Karl Trygve Kalleberg , 2002 -.SH SEE ALSO -gentool-package-size(1) -.TP -See \fI/usr/share/doc/gentoolkit-/\fR for documentation on other gentoolkit utilities. - diff --git a/trunk/src/gentool/gentool-package-size b/trunk/src/gentool/gentool-package-size deleted file mode 100755 index 7209a9a..0000000 --- a/trunk/src/gentool/gentool-package-size +++ /dev/null @@ -1,138 +0,0 @@ -#! /usr/bin/env python -# -# Copyright(c) 2002, Gentoo Technologies, Inc -# Copyright(c) 2002, Karl Trygve Kalleberg -# Distributed under the terms of the GNU General Public License v2 -# - -import sys -import string -import os -import os.path - -base = "/var/db/pkg" - -def getdirs(path): - files = os.listdir(path) - dirs = [] - for i in files: - if os.path.isdir(path + "/" + i): - dirs.append(i) - return dirs - -def findContentFile(spec): - k = string.split(spec,"/") - - if len(k) == 2: - cat = k[0] - pnm = k[1] - else: - cat = "" - pnm = k[0] - - if cat: - dirlist = os.listdir(base + "/" + cat) - for pkg in dirlist: - if string.find(pkg, pnm) == 0: - return (cat, pkg, base + "/" + cat + "/" + pkg + "/CONTENTS") - else: - cats = getdirs(base) - for cat in cats: - pkgs = getdirs(base + "/" + cat) - for pkg in pkgs: - if string.find(pkg, pnm) == 0: - return (cat, pkg, base + "/" + cat + "/" + pkg + "/CONTENTS") - return None - -def main(): - spec=sys.argv[1] - - try: - (cat, pkg, contents) = findContentFile(spec) - except: - print "No package resembling '" + spec + "' found" - sys.exit(-1) - - ins = open(contents) - - files = [] - inaccurate = 0 - total = 0 - for i in ins.readlines(): - k = string.split(i) - if len(k) and k[0] == "obj": - files.append(k[1]) - for i in files: - try: - total+=os.path.getsize(i) - except os.error: - inaccurate=1 - k = str(total) + " (" + str(total/1024) + "kiB)" - if inaccurate: - k += " ~" - print cat + "/" + pkg + " " + k - -if __name__ == "__main__": - main() - -""" -#!/bin/sh - -# Copyright(c) 2002, Gentoo Technologies, Inc -# Author: Karl Trygve Kalleberg - -spec=$1 - -name=`echo $1 | sed "s/\([^/]*\)\///"` -category=`echo $1 | sed "s/\/.*//"` - -if [ "$category" == "$name" ] ; then - category= -fi - -function tryfile() { - local foo - foo=/var/db/pkg/$1/CONTENTS - bar=`ls $foo 2> /dev/null` - for i in $bar ; do - if [ -f "$i" ] ; then - echo $i - break - fi - done -} - -file=`tryfile "${category}/${name}"` -if [ -z $file ] ; then - file=`tryfile "${category}/${name}*"` - if [ -z $file ] ; then - file=`tryfile "${category}*/${name}"` - if [ -z $file ] ; then - file=`tryfile "${category}*/${name}*"` - if [ -z $file ] ; then - echo "!!! Package resembling ${category}/${name} not found" - exit 1 - fi - fi - fi -fi - -pkgname=`echo $file | sed -e "s:\/var\/db\/pkg\/::" -e "s:\/CONTENTS::"` - -filelist=`cat $file|grep "obj"|awk '{ print $2 }' | sed "s/ /\\ /"` - -size=0 -for i in $filelist ; do - if [ -e $i ] ; then - s=`du -s $i | cut -f1` - size=$[size + s] - fi -done -#size=0 -#for i in $totals ; do -# size=$[size+i] -#done - -echo "$pkgname $size ($[size/1024]KB)" - -""" diff --git a/trunk/src/gentool/gentool-package-size.1 b/trunk/src/gentool/gentool-package-size.1 deleted file mode 100644 index 29408b0..0000000 --- a/trunk/src/gentool/gentool-package-size.1 +++ /dev/null @@ -1,44 +0,0 @@ -.TH gentool-package-size "1" "Nov 2002" "gentoolkit" -.SH NAME -gentool-package-size \- Calculates the diskspace occupied by a package -.SH SYNOPSIS -.B gentool-package-revision -\fIpackage-name\fR -.SH DESCRIPTION -The \fBgentool-package-revision\fR utility calculates the actual diskspace -taken by a given package. It will not consider the parition block size. The -package name need not be absolute, the closest match is sought. -.SH EXAMPLE -.LP -To look for the first package with a name starting with \fImozilla\fR: -.RS -.nf -\fBgentool-package-revision mozilla\fP -.fi -.RE - -.LP -To look for the first package in category \fInet-www\fR starting with -\fImozilla\fR: -.RS -.nf -\fBgentool-package-revision net-www/mozilla\fP -.fi -.RE - -.LP -To only match a very specific version of \fImozilla\fR in the -\fInet-www\fR category: -.RS -.nf -\fBgentool-package-revision net-www/mozilla-1.0.1-r3\fP -.fi -.RE - -.SH AUTHOR -Karl Trygve Kalleberg , 2002 -.SH SEE ALSO -gentool-package-count(1) -.TP -See \fI/usr/share/doc/gentoolkit-/\fR for documentation on other gentoolkit utilities. - diff --git a/trunk/src/gentool/gentool.1 b/trunk/src/gentool/gentool.1 deleted file mode 100644 index 0f52b7f..0000000 --- a/trunk/src/gentool/gentool.1 +++ /dev/null @@ -1,12 +0,0 @@ -.TH gentool "1" "Nov 2003" "gentoolkit" -.SH NAME -gentool \- Gentoo: Package Query Tool -.SH SYNOPSIS -.B gentool -.SH BUGS -This tool does not yet have a man page. Feel free to submit a bug about it to -http://bugs.gentoo.org -.SH AUTHORS -This informative man page was written by Karl Trygve Kalleberg -. - diff --git a/trunk/src/qpkg/ChangeLog b/trunk/src/qpkg/ChangeLog index e69de29..6cdc211 100644 --- a/trunk/src/qpkg/ChangeLog +++ b/trunk/src/qpkg/ChangeLog @@ -0,0 +1,2 @@ +2004-01-07 Karl Trygve Kalleberg + * Added Makefile diff --git a/trunk/src/qpkg/qpkg b/trunk/src/qpkg/qpkg index 41ff77b..fafb62e 100644 --- a/trunk/src/qpkg/qpkg +++ b/trunk/src/qpkg/qpkg @@ -1,210 +1,556 @@ -#! /usr/bin/env python2.2 -# -# Copyright 2003 Karl Trygve Kalleberg -# Copyright 2003 Gentoo Technologies, Inc. -# Distributed under the terms of the GNU General Public License v2 -# -# $Header$ -# Author: Karl Trygve Kalleberg -# +#!/bin/bash # # qpkg - query portage package system for various information # -# This is a reimplementation of the previous qpkg, written in bash, by -# Vitaly Kushneriuk , -# Brandon Low , -# Josh Goebel +# Copyright (c) Vitaly Kushneriuk +# This program is distributed under the terms of GPL version 2. +# +# Maintainer: Brandon Low +# Additional code thanks to: +# Josh Goebel # # $Header$ +ID='$Id$' +VERSION=0.`echo ${ID} | cut -d\ -f3` + +PROG=`basename ${0}` + +# Parse args +verb=0 +group="*" +params=${#} +while [ ${#} -gt 0 ] +do + a=${1} + shift + case "${a}" in + + -h|--help) + usage=y + break + ;; + + -i|--info) + info=y + ;; + + -d|--dups) + dups=y + inst=y + ;; + + -q|--query-deps) + query=y + ;; + + -s|--slot) + slot=y + ;; + + -f|--find-file) + ffind=y + inst=y + ;; + + -fp|--find-pattern) + ffind=y + fpat=y + inst=y + ;; + + -I|--installed) + inst=y + ;; + + -m|--masked) + grepmask="-L" + ;; + + -n|--non-masked) + grepmask="-l" + ;; + + -U|--uninstalled) + uninst=y + ;; + + -g|--group) + group=$1 + shift + ;; + + -l|--list) + list=y + inst=y + ;; + + -ct|--check-time|-tc|--time-check) + tcheck=y + inst=y + ;; + + -cm|--check-md5|-mc|--md5-check) + mcheck=y + inst=y + ;; + + -c|--check) + mcheck=y + tcheck=y + inst=y + ;; + + -v|--verbose) + let $((verb++)) + ;; + + -vv) + let $((verb++)) + let $((verb++)) + ;; + + -nc|--no-color|--nocolor|--no-colors|--nocolors) + nocolor=y + ;; + + -*) + echo -e ${CY}${PROG}${NO}:${YL} Invalid option ${RD}$a 1>&2 + usage=y + break + ;; + *) + if [ -n "${arg}" ]; then + echo -e ${CY}${PROG}: ${YL}Only one argument supported + usage=y + break + fi + arg=$a + ;; + + esac +done + +#This is a dumb way to handle things, take it out next time +T="\t" + +#Set up colors +if [ ! "${nocolor}" ]; then + NO="\x1b[0;0m" + BR="\x1b[0;01m" + CY="\x1b[36;01m" + RD="\x1b[31;01m" + GR="\x1b[32;01m" + YL="\x1b[33;01m" + BL="\x1b[34;01m" + STAR=" *" +elif [ ! "${inst}" ] && [ ! "${uninst}" ]; then + STAR=" *" +fi + + +# check for option conflicts +if [ "${inst}" -a "${uninst}" \ + -o \( "${ffind}" -o "${list}" -o "${tcheck}" -o "${mcheck}" \) \ + -a "${uninst}" ]; then + echo -e ${CY}${PROG}${NO}:${YL} conflicting options/modes${NO} + usage=y +fi + +if [ "${usage}" ]; then + echo -e "${CY}${PROG} v. ${VERSION}${NO} + +${CY}${PROG}${NO} is GenToolKit's \"query package\" tool, using it, you can +find packages owning files on your filesystem, check the integrity +of installed packages, and do other queries against installed or +uninstalled packages. + +${BR}Usage: +${T}${CY}${PROG}${NO} [${BR}options${NO}] [${YL}pkgname${NO}] [${BL}-g${YL} group${NO}] [${BL}-f${YL} ${NO}|${BL}-fp${YL} ${NO}] +${T}${CY}${PROG}${NO} ${BL}--dups${NO} [${BL}--slot${NO}] +${T}${CY}${PROG}${NO} ${BL}--help${NO} + +${BR}Duplicate Locating: + ${BL}-d, --dups${NO}${T}${T}print packages that have multiple versions installed + ${BL}-s, --slot${NO}${T}${T}make ${BL}-d${NO} SLOT only print dups of the same SLOT + +${BR}Package Selection: + ${BL}-f, --find-file${NO}${T}finds package that owns file + ${BL}-fp, --find-pattern${NO}${T}finds to package that owns file matching ** + ${BL}-m, --masked${NO}${T}${T}Include${YL} only${NO} masked packages + ${BL}-n, --non-masked${NO}${T}Include${YL} only${NO} non-masked packages + ${BL}-I, --installed${NO}${T}Include${YL} only${NO} installed packages + ${BL}-U, --uninstalled${NO}${T}Include${YL} only${NO} uninstalled packages + ${BL}-g, --group${NO}${T}${T}Find by group (can be combined with other searches) + +${BR}Information Selection: + ${BL}-l, --list${NO}${T}${T}List package content + ${BL}-i, --info${NO}${T}${T}Get package description and home page. + ${BL}-ct, --check-time${NO} + ${BL}-tc, --time-check${NO}${T}Verify package files timestamps + ${BL}-cm, --check-md5${NO} + ${BL}-mc, --md5-check${NO}${T}Verify package files md5 + ${BL}-c, --check${NO}${T}${T}Verify mtimes${YL} and${NO} md5. + ${BL}-q, --query-deps${NO}${T}display all installed packages +${T}${T}${T}depending on selected packages + +${BR}Operation Modifiers: + ${BL}-nc, --no-color${NO}${T}don't use colors + ${BL}-v, --verbose${NO}${T}Be more verbose [ can be repeated twice ] + ${BL}-vv${NO}${T}${T}${T}Same as ${BL}-v -v${NO} + +${YL}Notes${NO}: +${YL}*${NO} ${BL}-f${NO}, ${BL}-fp, ${BL}-d${NO}, ${BL}-l${NO}, ${BL}-ct${NO}, ${BL}-cm${NO}, and ${BL}-c${NO} apply only to installed packages. +${YL}*${NO} Short options may not be combined on the command-line, yet. +${YL}*${NO} The operation of some flags has been changed by the + stripping of version numbers from some output to see + the version numbers play with ${BL}-v${NO} and ${BL}-vv${NO}. +${YL}*${NO} When using${BL} -f${NO} with ${BL}-l${NO} or ${BL}--check.. -v${NO} options, only + matching files will be displayed, unless ${BL}-v${NO} is doubled, + (yet more verbose) or ${BL}-vv${NO} is used. + + +${YL}Examples${NO}: + ${PROG} --dups print duplicates oldest first + ${PROG} --dups -v .. with versions + ${PROG} print list of installed packages + ${PROG} porta -I print versions of installed portage + ${PROG} porta -i .. + versions in portage tree + descriptions + and homepages + ${PROG} gawk -c -v check integrity of all installed versions of gawk + the older ones will have \"damaged\" files. + ${PROG} -f /bin/ls print package(s) that own /bin/ls +" + exit +fi + +#For the --dups switch only +if [ "${dups}" ]; then +if [ "${grepmask}" ]; then + mask=`python -c 'import portage; print portage.settings["ACCEPT_KEYWORDS"];' 2> /dev/null` + echo -e "Currently accepted keywords: ${BL}${mask}${NO}" + echo -e + mask=`echo ${mask} | perl -pe 's/\s+/|/'` +fi + + #First dig out the list of packages with duplicates + find /var/db/pkg/ -iname "*${arg}*.ebuild" 2> /dev/null > /tmp/qpkg.lst + dups=`cat /tmp/qpkg.lst | cut -f7 -d/ | + sed -e 's:\.ebuild$::; s:-r[0-9]*$::; s:-[^-]*$::; /^$/d' | + sort | + uniq -d` + + #Next get all the exact versions + duppak=`cat /tmp/qpkg.lst | fgrep "${dups}"` + + #Now cut that down to the directory name so we can be smart + dirs=`sed -e 's:/[^/]*$::' /tmp/qpkg.lst` + + #Go through each package's DB and create a sortable file + #to play with + declare -i defcount=`cat /var/cache/edb/counter` + for DIR in ${dirs} + do #Package COUNTER + NUM=`cat "${DIR}/COUNTER" 2> /dev/null` + [ -z "${NUM}" ] && NUM=defcount + #Package slot if requested + [ ${slot} ] && SLOT=`cat "${DIR}/SLOT"` + #Package fullname + PKG=`ls --color=no -1 ${DIR}/*.ebuild|cut -f5,7 -d"/"` + #Package basename + NAME=`echo "${PKG}"|sed -e 's:\.ebuild$::; s:-r[0-9]\+$::; s:-[0-9].*$::'` + echo "${NUM} ${PKG} ${NAME}${SLOT}" + #Finish loop, and sort that nice sortable file based on + #installation order, and then based on package basename + #bash hates me so I decided to use a temp file + done |sort -t" " -k3 -k1g,2|uniq -D -f2 > /tmp/qpkg.lst + duppak=`cat /tmp/qpkg.lst` + rm /tmp/qpkg.lst + + #If max verbosity is set output with full path to each ebuild + if [ "${verb}" -gt 1 ]; then + echo -n "${duppak}"|cut -f2 -d" "| \ + sed -e "s:^:${BL}/var/db/pkg/${BR}:" \ + -e "s:\(/\)\([^/]*\)\(.ebuild\):\1${CY}\2${NO}\1\2\3:" + + #If normal verbosity output package group, package name and package version + elif [ "${verb}" -gt 0 ]; then + echo -n "${duppak}"|cut -f2 -d" "| \ + sed -e "s:\(^[^/]*/\)\(.*\)\(\.ebuild\):${BR}\1${CY}\2${NO}:" + + #Otherwise just output package group and package name + else + echo -n "${duppak}"|cut -f2 -d" "| \ + sed -e "s:-r[0-9]\+$::" \ + -e "s:-[0-9].*$::" \ + -e "s:\(^[^/]*/\)\(.*\):${BR}\1${CY}\2${NO}:"|uniq + fi + exit +fi + +# get list of ebuilds to work on +if [ "${ffind}" ]; then + # file find mode - list all ebuilds for + # package/CONTENTS containing + if [ "${fpat}" ]; then + dirs=`ls /var/db/pkg/${group}/*/CONTENTS \ + | xargs grep -l "${arg}" \ + | xargs --no-run-if-empty -n 1 dirname` + else + # if the user didnt specify a full path assume they + # want to check in the working dir #17331 + [ "${arg:0:1}" != "/" ] && arg="${PWD}/${arg}" + + dirs=`ls /var/db/pkg/${group}/*/CONTENTS \ + | xargs grep -l " ${arg}\( .*\)*$" \ + | xargs --no-run-if-empty -n 1 dirname` + fi + ipak=`( + for d in ${dirs} -;do + [ "-" = "$d" ] && break + ls ${d}/*.ebuild + done)` +else + # normal mode - list ebuilds for ebuild name containing + + # installed packages + if [ ! "${uninst}" ]; then + ipak=`find /var/db/pkg/ -iname "*.ebuild" 2>/dev/null` + if [[ ${group} != "*" ]]; then + ipak=`echo ${ipak}|sed -e "s: :\n:g"|grep ${group}` + fi + if [ ${arg} ]; then + # avoid ${arg}="db" from pulling in every installed package + temp="/var/db/pkg/.*${arg}" + ipak=`echo ${ipak}|sed -e "s: :\n:g"|grep -i ${temp}` + fi + if [ -n "${mask}" ]; then + ipak=`echo ${ipak}|xargs -r egrep ${grepmask} "^KEYWORDS=.*[[:space:]\"\'](${mask})[[:space:]\"\']"` + fi + fi + # not installed packages (yet:-) + if [ ! "${inst}" ]; then + upak=`find /usr/portage/ -iname "*.ebuild" 2>/dev/null|grep -v --regex="/usr/portage/[^/]*\.ebuild"` + if [[ ${group} != "*" ]]; then + upak=`echo ${upak}|sed -e "s: :\n:g"|grep ${group}` + fi + if [ ${arg} ]; then + upak=`echo ${upak}|sed -e "s: :\n:g"|grep -i ${arg}` + fi + if [ -n "${mask}" ]; then + upak=`echo ${upak}|xargs -r egrep ${grepmask} "^KEYWORDS=.*[[:space:]\"\'](${mask})[[:space:]\"\']"` + fi + fi +fi + +X="\([^/]*\)" + +for p in ${ipak} ${upak} -;do + [ "${p}" = "-" ] && break + + # cut common prefix from ebuild name and mark installed/uninstalled packages + # Note: iii/uuu will be replaced by the pipe at the end + n=${p%.ebuild} + var_db_pkg="/var/db/pkg/" + n=${n/${var_db_pkg}/iii } + usr_portage="/usr/portage/" + n=${n/${usr_portage}/uuu } + n=${n/\/*\//\/} + + d=${p%\/*.ebuild} # faster d=`dirname ${p}` + echo ${n} + + # if we have no passed parameters then + # we can skip the extra conditional checks + [[ ${params} == 0 ]] && continue; + + if [ "${mask}" ]; then + keywords=`grep KEYWORDS ${p}| cut -d\" -f2` + echo -e "${T}Keywords: ${BL}${keywords}${NO}" + fi + + if [ ${verb} -gt 1 ];then + echo "vvv ${p}" + fi + + if [ "${info}" ]; then + home=`grep HOMEPAGE ${p}| cut -d\" -f2` + desc=`grep DESCRIPTION ${p}| cut -d\" -f2` + echo -e "${T}${BL}${desc}${NO} [ ${YL}${home}${NO} ]" + if [ ${verb} -gt 0 ]; then + pdir=${p/$(basename ${p})/} + if [[ -r ${pdir}/USE && -r ${pdir}/IUSE ]]; then + echo -n "Compiled with USE Flags: " + for flag in $(<${pdir}/IUSE) + do + use=$(grep -o ${flag} ${pdir}/USE | tr -d '\n') + if [[ "${use}" == "" ]]; then + echo -n "-" + fi + echo -n "${flag} " + done + echo + fi + fi + fi + + if [ "${query}" ]; then + echo -e "${BL}DEPENDED ON BY:${NO}" + package="`echo ${n}|sed -e 's:-r[0-9]\+$::' \ + -e 's:-[0-9].*$::' \ + -e 's:^iii ::' \ + -e 's:^uuu ::'`" + place="`echo ${n}|cut -f1 -d' '`" + [[ "${place}" == "iii" ]] && color="${GR}" || color="${RD}" + + if [[ ${place} == "iii" ]]; then + for deppkg in $(grep -R "${package}" /var/db/pkg/*/*/RDEPEND | sed 's/RDEPEND.*$//') + do + rdepend=$(< ${deppkg}/RDEPEND) + + for flag in $(< ${deppkg}/USE) + do + if [[ "${flag:0:1}" == "-" ]]; then + rdepend=$(echo ${rdepend} | sed "s/${flag:1}? ( [[:alnum:][:punct:]]* )//") + fi + done + + if [[ $(echo ${rdepend} | grep -o ${package}) == ${package} ]]; then + echo $'\t'$(< ${deppkg}/PF) + fi + done + else + grep -R "${package}" /var/db/pkg/*/*/RDEPEND | \ + cut -f5,6 -d"/" | sed -e "s:^:\t${color}:;s:$:${NO}:" | sort -u + if [[ $(grep -R "*${package}" /etc/make.profile/packages) != "" ]]; then + echo -e "\t${color}SYSTEM PROFILE${NO}" + fi + fi + fi + + # cat package content, remove obj/sym/dir, md5 and mtime when not verbose + # display only match in file-find mode unless extra verbose + if [ "${list}" ]; then + echo -e ${BL}CONTENTS:${NO} + + if [ ${verb} -gt 1 ]; then + cat ${d}/CONTENTS + else + if [ "${ffind}" ]; then + if [ "${fpat}" ]; then + grep "${arg}" $d/CONTENTS + else + grep " ${arg}\( .*\)*$" $d/CONTENTS + fi + else + cat $d/CONTENTS + fi | + if [ ${verb} -gt 0 ]; then + cat + else + sed -e "s:\(^obj \)\([^ ]*\)\(.*$\):\1${BR}\2${NO}:; + s:\(^sym \)\([^ ]*\)\( -> \)\([^ ]*\)\(.*$\):\1${CY}\2${NO}\3\4:; + s:\(^dir \)\([^ ]*\)\(.*$\):\1${YL}\2${NO}:" + fi + fi + + echo + + # check files mtime and md5, display summary at the end + elif [ "${tcheck}" -o "${mcheck}" ]; then + # counters + fe=0 + fs=0 + # read the CONTENTS file and check md5 and mtime if needed + # process only matching files in find-file mode unless extra verbose + cat ${d}/CONTENTS | + if [ "${ffind}" -a ${verb} -lt 2 ];then + if [ "${fpat}" ]; then + grep "${arg}" + else + grep " ${arg} " + fi + else + cat + fi | + ( + while read -a line + do + fs=$((fs + 1)) + + unset md5 + unset _md5 + unset mtime + unset _mtime + unset err + + name=${line[1]} + + missing= + [ ! -e ${name} ] && missing=1 + + # colorize name and compute mtime/md5 + if [ "obj" = ${line[0]} ]; then + [ -e ${name} ] && { + [ "${tcheck}" ] && mtime=${line[3]} + [ "${tcheck}" ] && _mtime=`date -r ${name} +%s` + + [ "${mcheck}" ] && md5=${line[2]} + [ "${mcheck}" ] && _md5=`md5sum ${name}|cut -f1 -d" "` + } + + name=${BR}${name}${NO} + + elif [ "sym" = ${line[0]} ]; then + name=${CY}${name}${NO} + + elif [ "dir" = ${line[0]} ]; then + name=${YL}${name}${NO} + fi + + # compare + if [ "$missing" ]; then + err=1 + name="${name} ${RD}!not exist!${NO}" + fi + if [ "${md5}" != "${_md5}" ]; then + #If the md5 fails the first time check it with + #everything changed to lowercase :-D + md5=`echo "${md5}"|tr A-Z a-z` + if [ "${md5}" != "${_md5}" ]; then + err=1 + name="${name} ${RD}!md5!${NO}" + fi + fi + if [ "${mtime}" != "${_mtime}" ]; then + err=1 + name="${name} ${RD}!mtime!${NO}" + fi + + [ ${verb} -gt 1 ] && echo -e ${name} + [[ ${verb} -eq 1 ]] && [[ $err -eq 1 ]] && echo -e ${name} + + fe=$((fe + err)) + done + if [ "$fe" = "0" ]; then + echo -e ${YL}$fe${CY}/$fs${NO} + else + echo -e ${RD}$fe${CY}/$fs${NO} + fi + echo + ) + fi + +done | ( + if [ ! \( "${tcheck}" -o "${mcheck}" -o "${info}" -o "${list}" -o "${query}" -o "${mask}" -o ${verb} -gt 0 \) ]; then + sed -e "s:-r[0-9]\+$::" -e "s:-[0-9][^-]*$::"|sort -k2|uniq -f1 + elif [ ! \( "${tcheck}" -o "${mcheck}" -o "${info}" -o "${list}" -o "${query}" -o "${mask}" -o ${verb} -lt 2 \) ]; then + sort -k2|uniq -f1 + else + cat + fi | sed \ + -e "s:^iii ${X}/${X}:${BR}\1/${CY}\2${STAR}${NO}:" \ + -e "s:^uuu ${X}/${X}:${BR}\1/${YL}\2${NO}:" \ + -e "s:^vvv \(.*\)$:${BL}\1${NO}:" \ + -e "s:^obj ::;s:^sym ::;s:^dir ::" -import sys -from output import * - -__author__ = "Karl Trygve Kalleberg" -__email__ = "karltk@gentoo.org" -__version__ = "0.2.0" -__productname__ = "qpkg" -__description__ = "Query Portage package system CLI tool" - -class Config: - showUsage=0 - pass - -def showUsage(): - - print turquoise("qpkg") + " v" + __version__ + " - Gentoo package query tool" - - print white("Usage:") - - print "\t" + turquoise("qpkg") + " " +\ - "[" + white("options") + "] " + \ - "[" + yellow("pkgname") + "] " + \ - "[" + blue("-g") + " " + yellow("group") + "] " + \ - "[" + blue("-f") + " " + yellow("") + "|" + blue("-fp") + " " + yellow("" - print blue("-fp, --find-pattern") + "\tfinds package that owns file matching **" - print blue("-m, --masked") + "\t\tinclude " + yellow("only") + " masked packages" - print blue("-n, --non-masked") + "\tinclude " + yellow("only") + " installed packages" - print blue("-U, --uninstalled") + "\tinclude " + yellow("only") + " uninstalled packages" - print blue("-g, --group") + "\t\tfind by group (can be combined with other searches" - - print "\n" + white("Information selection:") - print blue("-l, --list") + "\t\tlist package content" - print blue("-i, --info") + "\t\tget package description and home page" - print blue("-ct, --check-time") - print blue("-tc, --time-check") + "\tverify package files' time stamps" - print blue("-cm, --check-md5") - print blue("-mc, --md5-check") + "\tverify package files md5" - print blue("-c, --check") + "\t\tverify mtimes " + yellow("and") + "md5" - print blue("-q, --query-deps") + "\tdisplay all installed packages" + \ - "\n\t\t\tdepending on selected packages" - - print "\n" + white("Operation modifiers:") - print blue("-nc, --no-color") + "\tdo not use colors" - print blue("-v, --verbose") + "\tincrease verbosity [ can be repeated twice ]" - print blue("-vv") + "\t\tsame as " + blue("-v -v") - - print "\n" + yellow("Notes") - print yellow("*") + " " + blue("-f, -fp, -d, -l, -ct, -cm") + " and " + \ - blue("-c") + " apply only to installed packages" - print yellow("*") + " short options may not be combined on the command-line, yet" - print yellow("*") + " the operation of some flags has been changed by the " + \ - "stripping of version\n" + \ - " numbers from some output to see the version numbers play with " + \ - blue("-v") + " and " + blue("-vv") - print yellow("*") + " when using " + blue("-f") + " with " + blue("-l") + \ - " or " + blue("--check.. -v") + " options, only matching files will be\n" + \ - " displayed, unless " + blue("-v") + " is doubled, or " + blue("--vv") + " is used" - - print "\n" + yellow("Examples:") - print "qpkg --dups print duplicates oldest first" - print "qpkg --dups -v ... with versions" - print "qpkg print list of installed packages" - print "qpkg porta -I print versions of installed portage" - print "qpkg porta -i ... + versions in portage tree + descriptions and homepages" - print "qpkg gawk -c -v check integrity of all installed versions of gawk, the\n" + \ - "\t\t\tolder will have \"damaged\" files" - print "qpkg -f /bin/ls print package(s) that own /bin/ls" - -def setupConfigDefaults(): - Config.verbosity = 0 - Config.color = 1 - Config.showUsage = 0 - Config.showPackageContents = 0 - Config.showInstalled = 0 - Config.showMasked = 0 - Config.showDeps = 0 - Config.showSlot = 0 - Config.findFile = 0 - Config.checkMD5 = 0 - Config.checkTime = 0 - -def parseArgs(): - setupConfigDefaults() - - if len(sys.argv) < 2: - Config.showUsage = 1 - return - - args=sys.argv[1:] - skip=0 - for x in range(len(args)): - # FIXME: Nasty skippery hackery - if skip: - skip-=1 - continue - i=args[x] - if 0: - pass - elif i in ["-h","--help"]: - Config.showUsage = 1 - elif i in ["-i","--info"]: - Config.showInfo = 1 - elif i in ["-d","--dups"]: - Config.showDups = 1 - Config.showInstalled = 1 - elif i in ["-q","--query-deps"]: - Config.showDeps = 1 - elif i in ["-s","--slot"]: - Config.showSlot = 1 - elif i in ["-f","--find-file"]: - Config.findFile = 1 - Config.showInstalled = 1 - elif i in ["-fp","--find-pattern"]: - Config.findFile = 1 - Config.findFilePattern = 1 - Config.showInstalled = 1 - elif i in ["-I","--installed"]: - Config.showInstalled = 1 - elif i in ["-m", "--masked"]: - Config.showMasked = 1 - elif i in ["-n", "--non-masked"]: - Config.showMasked = 0 - elif i in ["-U","--uninstalled"]: - Config.showInstalled = 0 - elif i in ["-g","--group"]: - Config.showCategory = args[x+1] - skip=1 - elif i in ["-l", "--list"]: - Config.showPackageContents = 1 - Config.showInstalled = 1 - elif i in ["-ct","--check-time","-tc","--time-check"]: - Config.checkTime = 1 - Config.showInstalled = 1 - elif i in ["-cm","--check-md5","-mc","--md5-check"]: - Config.checkMD5 = 1 - Config.showInstalled = 1 - elif i in ["-v","--verbose"]: - Config.verbosity += 1 - elif i in ["-vv"]: - Config.verbosity += 2 - elif i in ["-nc","--no-color","--nocolor","--no-colors"]: - Config.color = 0 - else: - print "xx:", i - Config.showUsage=1 - break - -def showPackageContents(): - print "showPackageContents" - -def checkMD5(): - print "checkMD5" - -def checkTimeStamps(): - print "checkTimeStamps" - -def findFile(): - print "findFile" - -def showDeps(): - print "showDeps" - -def main(): - parseArgs() - if Config.showUsage: - showUsage() - elif Config.showPackageContents: - showPackageContents() - elif Config.checkMD5: - checkMD5() - elif Config.checkTime: - checkTimeStamps() - elif Config.findFile: - findFile() - elif Config.showDeps: - showDeps() - else: - raise "Don't know what do do..." - -if __name__ == "__main__": - main() +) diff --git a/trunk/src/qpkg/qpkg.1 b/trunk/src/qpkg/qpkg.1 index e4164ea..6d45a93 100644 --- a/trunk/src/qpkg/qpkg.1 +++ b/trunk/src/qpkg/qpkg.1 @@ -1,6 +1,6 @@ .TH "qpkg" "1" "1.6" "gentoolkit 0.1.11-r1" "" .SH "NAME" -qpkg \- the "query package" tool for Gentoo Linux +qpkg \- Gentoo: query package tool .SH "SYNOPSIS" .LP .B qpkg\fR [\fIoptions\fR] [\fIpkgname\fR] [\fI\-g group\fR] diff --git a/trunk/src/revdep-rebuild/Makefile b/trunk/src/revdep-rebuild/Makefile index 1150d0d..5c68147 100644 --- a/trunk/src/revdep-rebuild/Makefile +++ b/trunk/src/revdep-rebuild/Makefile @@ -15,7 +15,7 @@ dist: install: - install -m 0755 revdep-rebuild $(sbindir)/ + install -m 0755 revdep-rebuild $(bindir)/ install -d $(docdir)/revdep-rebuild install -m 0644 {AUTHORS,README,TODO} $(docdir)/revdep-rebuild/ install -m 0644 revdep-rebuild.1 $(mandir)/ -- cgit v1.2.3