catch KeyError and ValueError thrown by portage on invalid/ambiguous package names
authorgenone <genone@gentoo.org>
Fri, 23 Jan 2004 02:51:09 +0000 (02:51 -0000)
committergenone <genone@gentoo.org>
Fri, 23 Jan 2004 02:51:09 +0000 (02:51 -0000)
svn path=/; revision=68

trunk/src/equery/equery
trunk/src/etcat/etcat

index b99139339937e108a36d4cbf93aff33cecbafd01..099bc336c3a92e4f9c8e70efda5db35e1321a0d2 100755 (executable)
@@ -920,7 +920,22 @@ def parseArgs(args):
 if __name__ == "__main__":
        (cmd, local_opts) = parseArgs(sys.argv[1:])
        if cmd:
-               cmd.perform(local_opts)
+               try:
+                       cmd.perform(local_opts)
+               except KeyError, e:
+                       print red("!!!"), "Invalid syntax: missing operator"
+                       print red("!!!"), "If you want only specific versions please use one of"
+                       print red("!!!"), "the following operators as prefix for the package name:"
+                       print red("!!!"), "   >  >=  =  <=  <"
+                       print red("!!!"), "Example to only match gcc versions greater or equal 3.2:"
+                       print red("!!!"), "   >=sys-devel/gcc-3.2"
+                       sys.exit(2)
+               except ValueError, epkg:
+                       print red("!!!"), "Ambiguous package name \"%s\"" % query
+                       print red("!!!"), "Please use one of the following long names:"
+                       for p in epkg[0]:
+                               print red("!!!"), "    "+p
+                       sys.exit(2)
        else:
                print "No command or unknown command given"
                printUsage()
index 99d0739f4883b0c3e0287225c66c0c2dab154069..e5e726a11fb6daa1f5bfc3319a7c838a0b331a1e 100755 (executable)
@@ -222,8 +222,7 @@ def output_log(lines, package_ver=""):
 # | Print out the ChangeLog entry for package[-version]   |
 # `-------------------------------------------------------'
 
-def changes(query):
-       matches=gentoolkit.find_packages(query)
+def changes(query, matches):
        if not report_matches(query,matches,installed_only=0):
                return
 
@@ -242,8 +241,7 @@ def changes(query):
 # | installed status.                                                                   |
 # `-------------------------------------------------------'            
                
-def versions(query):
-       matches = gentoolkit.find_packages(query)
+def versions(query, matches):
        if not report_matches(query,matches):
                return
 
@@ -299,10 +297,7 @@ def versions(query):
 # +-------------------------------------------------------+
 # | Just uses the new IUSE parameter in ebuilds                   |
 # `-------------------------------------------------------' 
-def uses(query):
-       
-       matches = gentoolkit.find_packages(query)
-               
+def uses(query, matches):
        useflags = gentoolkit.settings["USE"].split()   
        usedesc = {}
        uselocaldesc = {}
@@ -409,8 +404,7 @@ def uses(query):
 # | Naive graphing of dependencies
 # `-------------------------------------------------------'
 
-def graph(query):
-       matches = gentoolkit.find_packages(query)
+def graph(query, matches):
        if not report_matches(query, matches):
                return
 
@@ -447,13 +441,13 @@ def rgraph(pkg,level=0,pkgtbl=[],suffix=""):
 # | Find what packages require a given package name       |
 # `-------------------------------------------------------'
 
-def depends(query):
+def depends(query, matches):
        
        print "[ Results for search key : " + white(query) + " ]"
 
        isdepend = gentoolkit.split_package_name(query)
        
-       for pkg in gentoolkit.find_all_packages():
+       for pkg in matches:
                if pkg.is_installed():
                        deps = pkg.get_runtime_deps()
                        for x in deps:
@@ -611,7 +605,7 @@ def main():
        # delegates the commandline stuff to functions
        pointer = 2
        # short/long opts mapping
-       shortopts = map(lambda x: "-" + x[0], options.values())
+       shortopts = ["-"+x[0] for x in options.values()]
        short2long = {}
        for k,v in options.items():
                short2long[v[0]] = k
@@ -634,8 +628,24 @@ def main():
                help()
                sys.exit(1)
        else:
+               try:
+                       matches = gentoolkit.find_packages(query)
+               except KeyError, e:
+                       print red("!!!"), "Invalid syntax: missing operator"
+                       print red("!!!"), "If you want only specific versions please use one of"
+                       print red("!!!"), "the following operators as prefix for the package name:"
+                       print red("!!!"), "   >  >=  =  <=  <"
+                       print red("!!!"), "Example to only match gcc versions greater or equal 3.2:"
+                       print red("!!!"), "   >=sys-devel/gcc-3.2"
+                       sys.exit(2)
+               except ValueError, epkg:
+                       print red("!!!"), "Ambiguous package name \"%s\"" % query
+                       print red("!!!"), "Please use one of the following long names:"
+                       for p in epkg[0]:
+                               print red("!!!"), "    "+p
+                       sys.exit(2)
                function = globals()[action]
-               function(query)
+               function(query, matches)
        
 if __name__ == "__main__":
        try: