fixed Exception handling for other errors
authorgenone <genone@gentoo.org>
Fri, 23 Jan 2004 03:35:08 +0000 (03:35 -0000)
committergenone <genone@gentoo.org>
Fri, 23 Jan 2004 03:35:08 +0000 (03:35 -0000)
svn path=/; revision=69

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

index 099bc336c3a92e4f9c8e70efda5db35e1321a0d2..24d3aa37dfc30b0fdb8d30555223550e24f1adec 100755 (executable)
@@ -17,6 +17,7 @@ import re
 import sys
 import time
 import string
+import types
 
 # portage (output module) and gentoolkit need special path modifications
 sys.path.insert(0, "/usr/lib/portage/pym")
@@ -923,18 +924,28 @@ if __name__ == "__main__":
                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"
+                       if string.find(e[0], "Specific key requires operator") == 0:
+                               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"
+                       else:
+                               print red("!!!"), "Internal portage error, terminating"
+                               if len(e[0]):
+                                       print red("!!!"), e
                        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
+               except ValueError, e:
+                       if type(e[0]) == types.ListType:
+                               print red("!!!"), "Ambiguous package name \"%s\"" % query
+                               print red("!!!"), "Please use one of the following long names:"
+                               for p in e[0]:
+                                       print red("!!!"), "    "+p
+                       else:
+                               print red("!!!"), "Internal portage error, terminating"
+                               if len(e[0])):
+                                       print red("!!!"), e[0]
                        sys.exit(2)
        else:
                print "No command or unknown command given"
index e5e726a11fb6daa1f5bfc3319a7c838a0b331a1e..2ef5b9ffaad30a31c1cd41c87b7afdecfdac5b44 100755 (executable)
@@ -78,7 +78,7 @@
 
 
 
-import os,sys,string,re,pprint
+import os,sys,string,re,pprint,types
 import getopt,glob
 
 # portage and gentoolkit need special path modifications
@@ -631,18 +631,28 @@ def main():
                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"
+                       if string.find(e[0], "Specific key requires operator") == 0:
+                               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"
+                       else:
+                               print red("!!!"), "Internal portage error, terminating"
+                               if len(e[0]):
+                                       print red("!!!"), e
                        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
+               except ValueError, e:
+                       if type(e[0]) == types.ListType:
+                               print red("!!!"), "Ambiguous package name \"%s\"" % query
+                               print red("!!!"), "Please use one of the following long names:"
+                               for p in e[0]:
+                                       print red("!!!"), "    "+p
+                       else:
+                               print red("!!!"), "Internal portage error, terminating"
+                               if len(e[0])):
+                                       print red("!!!"), e[0]
                        sys.exit(2)
                function = globals()[action]
                function(query, matches)