3rd try, bugfixes, cleanups and a little new feature
authorgenone <genone@gentoo.org>
Fri, 9 Jan 2004 00:49:14 +0000 (00:49 -0000)
committergenone <genone@gentoo.org>
Fri, 9 Jan 2004 00:49:14 +0000 (00:49 -0000)
svn path=/; revision=52

trunk/src/equery/equery
trunk/src/etcat/etcat
trunk/src/gentoolkit/gentoolkit.py

index f139aeedb158a04ba13499f1282a9c7a287ebc53..e54575dddddd93509e7a05e40110c2384a736c7f 100755 (executable)
@@ -9,7 +9,7 @@
 
 __author__ = "Karl Trygve Kalleberg"
 __email__ = "karltk@gentoo.org"
-__version__ = "0.1.0"
+__version__ = "0.1.1"
 __productname__ = "equery"
 __description__ = "Gentoo Package Query Tool"
 
@@ -17,12 +17,12 @@ import re
 import sys
 import time
 import string
-from output import *
 
-sys.path = ["/usr/lib/portage/pym"] + \
-           ["/usr/lib/gentoolkit/pym"] + \
-           sys.path
+# portage (output module) and gentoolkit need special path modifications
+sys.path.insert(0, "/usr/lib/portage/pym")
+sys.path.insert(0, "/usr/lib/gentoolkit/pym")
 
+from output import *
 import gentoolkit
 
 # Auxiliary functions
@@ -144,7 +144,7 @@ class CmdListFiles(Command):
                "  " + yellow("--md5sum") + "     - append md5sum\n" + \
                "  " + yellow("--type") + "       - prepend file type"               
     def shortHelp(self):
-        return yellow("<local-opts> ") + teal("pkgspec") + " - list files owned by " + teal("pkgspec")
+        return yellow("<local-opts> ") + turquoise("pkgspec") + " - list files owned by " + turquoise("pkgspec")
 
     
 class CmdListBelongs(Command):
@@ -213,7 +213,7 @@ class CmdListBelongs(Command):
                 break
                     
     def shortHelp(self):
-        return yellow("<local-opts> ") + teal("file") + " - list all packages owning " + teal("file")
+        return yellow("<local-opts> ") + turquoise("file") + " - list all packages owning " + turquoise("file")
     def longHelp(self):
         return "List all packages owning a particular file" + \
                "\n" + \
@@ -221,7 +221,7 @@ class CmdListBelongs(Command):
                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(" <local-opts> ") + teal("filename") + \
+               "  " + green("belongs") + yellow(" <local-opts> ") + turquoise("filename") + \
                "\n" + \
                yellow("<local-opts>") + " is either of: \n" + \
                "  " + yellow("-c, --category cat") + " - only search in category " + yellow("cat") + "\n" + \
@@ -364,12 +364,12 @@ class CmdDisplayUSEs(Command):
             else:
                 print "[ No USE flags found for :", white(p.get_cpv()), "]"
     def shortHelp(self):
-        return yellow("<local-opts> ") + teal("pkgspec") + " - display USE flags for " + teal("pkgspec")
+        return yellow("<local-opts> ") + turquoise("pkgspec") + " - display USE flags for " + turquoise("pkgspec")
     def longHelp(self):
         return "Display USE flags for a given package\n" + \
                "\n" + \
                "Syntax:\n" + \
-               "  " + green("uses") + yellow(" <local-opts> ") + teal("pkgspec") + \
+               "  " + green("uses") + yellow(" <local-opts> ") + turquoise("pkgspec") + \
                "\n" + \
                yellow("<local-opts>") + " is either of: \n"
 
@@ -454,12 +454,12 @@ class CmdDisplayDepGraph(Command):
         return pkgtbl
 
     def shortHelp(self):
-        return yellow("<local-opts> ") + teal("pkgspec") + " - display a dependency tree for " + teal("pkgspec")
+        return yellow("<local-opts> ") + turquoise("pkgspec") + " - display a dependency tree for " + turquoise("pkgspec")
     def longHelp(self):
         return "Display a dependency tree for a given package\n" + \
                "\n" + \
                "Syntax:\n" + \
-               "  " + green("depgraph") + yellow(" <local-opts> ") + teal("pkgspec") + \
+               "  " + green("depgraph") + yellow(" <local-opts> ") + turquoise("pkgspec") + \
                "\n" + \
                yellow("<local-opts>") + " is either of: \n" + \
                "  " + yellow("-U, --no-useflags") + " - do not show USE flags\n" + \
@@ -525,12 +525,12 @@ class CmdDisplaySize(Command):
 
                     
     def shortHelp(self):
-        return yellow("<local-opts> ") + teal("pkgspec") + " - print size of files contained in package " + teal("pkgspec")
+        return yellow("<local-opts> ") + turquoise("pkgspec") + " - print size of files contained in package " + turquoise("pkgspec")
     def longHelp(self):
         return "Print size total size of files contained in a given package" + \
                "\n" + \
                "Syntax:\n" + \
-               "  " + green("size") + yellow(" <local-opts> ") + teal("pkgspec") + \
+               "  " + green("size") + yellow(" <local-opts> ") + turquoise("pkgspec") + \
                "\n" + \
                yellow("<local-opts>") + " is either of: \n" + \
                "  " + yellow("-b, --bytes") + " - report size in bytes\n"
@@ -628,7 +628,7 @@ class CmdCheckIntegrity(Command):
                     print file + " does not exist"
                     
     def shortHelp(self):
-        return teal("pkgspec") + " - check package's files against recorded MD5 sums and timestamps"
+        return turquoise("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"
 
@@ -677,7 +677,7 @@ class CmdWhich(Command):
             print os.path.normpath(pkg.get_ebuild_path())
                     
     def shortHelp(self):
-        return teal("pkgspec") + " - print full path to ebuild for package " + teal("pkgspec")
+        return turquoise("pkgspec") + " - print full path to ebuild for package " + turquoise("pkgspec")
     def longHelp(self):
         return "Print full path to ebuild for a given package"
 
@@ -790,17 +790,17 @@ class CmdListPackages(Command):
 
             if (status == 1 and opts["includeInstalled"]) or \
                (status == 2 and opts["includePortTree"]) or \
-               (status == 3 and opts["includeOverlay"]):
+               (status == 3 and opts["includeOverlayTree"]):
                 if rx.search(pkg.get_cpv()):
                     print pfxmodes[status] + " " + pkg.get_cpv()
                     
     def shortHelp(self):
-        return yellow("<local-opts> ") + teal("pkgspec") + " - list all packages matching " + teal("pkgspec")
+        return yellow("<local-opts> ") + turquoise("pkgspec") + " - list all packages matching " + turquoise("pkgspec")
     def longHelp(self):
         return "List all packages matching a query pattern" + \
                "\n" + \
                "Syntax:\n" + \
-               "  " + green("list") + yellow(" <local-opts> ") + teal("pkgspec") + \
+               "  " + green("list") + yellow(" <local-opts> ") + turquoise("pkgspec") + \
                "\n" + \
                yellow("<local-opts>") + " is either of: \n" + \
                "  " + yellow("-i, --installed") + "         - search installed packages (default)\n" + \
@@ -864,24 +864,26 @@ def parseArgs(args):
 
     command = None
     local_opts = []
-
+    showhelp = 0
+       
     for i in xrange(len(args)):
         x = args[i]
         if 0:
             pass
         elif x in ["-h","--help"]:
-            printUsage()
-            sys.exit(0)
+                       showhelp = 1
         elif x in ["-V","--version"]:
             printVersion()
             sys.exit(0)
         elif x in ["-C","--nocolor"]:
-            Config.color = 0
+            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:]
+            if showhelp:
+                local_opts.append("--help")
             break
         
     # Set up colour output correctly
@@ -892,10 +894,16 @@ def parseArgs(args):
          Config["color"] == 0:
             nocolor()
 
+    if not command and showhelp:
+        printUsage()
+        sys.exit(0)
+
     return (command, local_opts)
     
 if __name__ == "__main__":
     (cmd, local_opts) = parseArgs(sys.argv[1:])
     if cmd:
         cmd.perform(local_opts)
-
+    else:
+        print "No command or unknown command given"
+        printUsage()
index 7c3737c1f8c78fd91eeb75c334d91fe2ce7eb15e..5368f0929dfc1ff266989aec13b6fc7b3ed64dbb 100755 (executable)
@@ -42,6 +42,9 @@
 # 
 # --| Changes |------------------------------------------------------
 #
+#  * etcat-0.3.1 (08 Jan 2004) [genone]
+#    - adding missing python searchpath modification
+#    - fixing sort order
 #  * etcat-0.3.0 (12 Jul 2003) [karltk]
 #    - Refactored interesting stuff into the Gentoolkit module
 #  * etcat-0.2.0 (13 Jun 2003)
 
 import os,sys,string,re,pprint
 import getopt,glob
+
+# portage and gentoolkit need special path modifications
+sys.path.insert(0, "/usr/lib/portage/pym")
+sys.path.insert(0, "/usr/lib/gentoolkit/pym")
+
 import gentoolkit
 from stat import *
 from output import *
 
 __author__ = "Alastair Tse"
 __email__ = "liquidx@gentoo.org"
-__version__ = "0.2.0"
+__version__ = "0.3.1"
 __productname__ = "etcat"
 __description__ = "Portage Information Extractor"
 
-# .-------------------------------------------------------.
-# | Initialise Paths                                      |
-# `-------------------------------------------------------'
-
-sys.path = ["/usr/lib/portage/pym"] + sys.path
-
 # .-------------------------------------------------------.
 # | Initialise Colour Settings                            |
 # `-------------------------------------------------------'
@@ -230,6 +232,9 @@ def versions(query):
     if not report_matches(query,matches):
         return
 
+       # sorting result list
+    matches = gentoolkit.sort_package_list(matches)
+       
     # FIXME: old version printed result of regex search on name,
     # so "ant" would return app-emacs/semantic, etc...
     
index ffab7306824b2b1be4fa981a0aefccfa78f60637..cf499a44798b0ff3406e2ceb4789ef02fe51d0aa 100644 (file)
@@ -18,6 +18,8 @@ __productname__ = "gentoolkit"
 __description__ = "Gentoolkit Common Library"
 
 import os
+import sys
+sys.path.insert(0, "/usr/lib/portage/pym")
 import portage
 import re
 import string
@@ -38,6 +40,8 @@ class Package:
     def __init__(self,cpv):
         self._cpv = cpv
         self._scpv = portage.catpkgsplit(self._cpv)
+        if not self._scpv:
+            raise Exception("invalid cpv: %s" % cpv)
         self._db = None
         self._settings = None
     def get_name(self):
@@ -124,7 +128,7 @@ class Package:
             return string.join(sp[:-1],"/")
     def get_env_var(self, var):
         """Returns one of the predefined env vars DEPEND, RDEPEND, SRC_URI,...."""
-        r=vartree.dbapi.aux_get(self._cpv,[var])
+        r=porttree.dbapi.aux_get(self._cpv,[var])
         if not r:
             raise "WTF??"
         if len(r)!=1:
@@ -146,7 +150,7 @@ class Package:
     def compare_version(self,other):
         """Compares this package's version to another's CPV; returns -1, 0, 1"""
         v1=self._scpv
-        v2=portage.catpkgsplit(other)
+        v2=portage.catpkgsplit(other.get_cpv())
         if v1[0] != v2[0] or v1[1] != v2[1]:
             return None
         return portage.pkgcmp(v1[1:],v2[1:])
@@ -233,18 +237,16 @@ def find_world_packages(prefilter=None):
 def find_all_installed_packages(prefilter=None):
     """Returns a list of all installed packages, after applying the prefilter
     function"""
-    t=vartree.getallcpv()
+    t=vartree.cpv_all()
     if prefilter:
         t=filter(prefilter,t)
-    return map(lambda x: Package(x), t)
+    return [Package(x) for x in t]
 
 def find_all_uninstalled_packages(prefilter=None):
     """Returns a list of all uninstalled packages, after applying the prefilter
     function"""
-    t=porttree.getallcpv()
-    if prefilter:
-        t=filter(prefilter,t)
-    return map(lambda x: Package(x), t)
+    alist = find_all_packages(prefilter)
+    return [x for x in alist if not x.is_installed()]
 
 def find_all_packages(prefilter=None):
     """Returns a list of all known packages, installed or not, after applying
@@ -255,7 +257,7 @@ def find_all_packages(prefilter=None):
     t2=[]
     for x in t:
         t2 += portage.portdb.cp_list(x)
-    return map(lambda x: Package(x), t2)
+    return [Package(x) for x in t2]
 
 def split_package_name(name):
     """Returns a list on the form [category, name, version, revision]. Revision will
@@ -272,6 +274,12 @@ def split_package_name(name):
         r[0] = ''
     return r
 
+def sort_package_list(pkglist):
+       """Returns the list ordered in the same way portage would do with lowest version
+       at the head of the list."""
+       pkglist.sort(Package.compare_version)
+       return pkglist
+
 if __name__ == "__main__":
     print "This module is for import only"