Bug #194764 - All the match* functions can raise
authorZac Medico <zmedico@gentoo.org>
Fri, 5 Oct 2007 04:20:14 +0000 (04:20 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 5 Oct 2007 04:20:14 +0000 (04:20 -0000)
a ValueError if cpv_expand() receives an ambiguous
atom. Therefore, move the ValueError handling code
out of match() and use it to handle all such errors
when appropriate.

svn path=/main/trunk/; revision=7944

bin/portageq

index 99bf49bc282b76380a5a505904884d55c88178fb..d97f08cb0bc64dd7cd643b43bccf2f0b8f277801 100755 (executable)
@@ -183,15 +183,6 @@ def match(argv):
                sys.exit(2)
        try:
                print "\n".join(portage.db[argv[0]]["vartree"].dbapi.match(argv[1]))
-       except ValueError, e:
-               # Multiple matches thrown from cpv_expand
-               pkgs = e.args[0]
-               # An error has occurred so we writemsg to stderr and exit nonzero.
-               portage.writemsg("The following packages available:\n", noiselevel=-1)
-               for pkg in pkgs:
-                       portage.writemsg("* %s\n" % pkg, noiselevel=-1)
-               portage.writemsg("\nPlease use a more specific atom.\n", noiselevel=-1)
-               sys.exit(1)
        except KeyError, e:
                portage.writemsg("%s\n" % str(e), noiselevel=-1)
                sys.exit(1)
@@ -389,6 +380,19 @@ def main():
        except portage.exception.PermissionDenied, e:
                sys.stderr.write("Permission denied: '%s'\n" % str(e))
                sys.exit(e.errno)
+       except ValueError, e:
+               if not e.args or \
+                       not hasattr(e.args[0], "__len__") or \
+                       len(e.args[0]) < 2:
+                       raise
+               # Multiple matches thrown from cpv_expand
+               pkgs = e.args[0]
+               # An error has occurred so we writemsg to stderr and exit nonzero.
+               portage.writemsg("The following packages available:\n", noiselevel=-1)
+               for pkg in pkgs:
+                       portage.writemsg("* %s\n" % pkg, noiselevel=-1)
+               portage.writemsg("\nPlease use a more specific atom.\n", noiselevel=-1)
+               sys.exit(1)
 
 main()