Sanitize getopt exception handling
authorDanek Duvall <danek.duvall@sun.com>
Sun, 01 Jul 2007 12:28:14 -0700
changeset 52 d7c452ef7ae1
parent 51 d04d55e16d0b
child 53 68b135443ad9
Sanitize getopt exception handling
src/client.py
src/depot.py
src/publish.py
--- a/src/client.py	Thu Jun 28 15:33:59 2007 -0700
+++ b/src/client.py	Sun Jul 01 12:28:14 2007 -0700
@@ -234,8 +234,8 @@
         try:
                 if len(sys.argv) > 1:
                         opts, pargs = getopt.getopt(sys.argv[1:], "s:R:")
-        except:
-                print "pkg: illegal global option(s)"
+        except getopt.GetoptError, e:
+                print "pkg: illegal global option '%s'" % e.opt
                 usage()
 
         if pargs == None or len(pargs) == 0:
--- a/src/depot.py	Thu Jun 28 15:33:59 2007 -0700
+++ b/src/depot.py	Sun Jul 01 12:28:14 2007 -0700
@@ -47,6 +47,7 @@
 import re
 import sha
 import shutil
+import sys
 import time
 import urllib
 
@@ -246,8 +247,8 @@
                 for opt, arg in opts:
                         if opt == "-n":
                                 sys.exit(0)
-        except:
-                print "pkg.depotd: unknown option"
+        except getopt.GetoptError, e:
+                print "pkg.depotd: unknown option '%s'" % e.opt
                 usage()
 
         server = BaseHTTPServer.HTTPServer(('', 10000), pkgHandler)
--- a/src/publish.py	Thu Jun 28 15:33:59 2007 -0700
+++ b/src/publish.py	Sun Jul 01 12:28:14 2007 -0700
@@ -82,8 +82,8 @@
         pargs = None
         try:
                 opts, pargs = getopt.getopt(args, "e")
-        except:
-                print "pkgsend: illegal open option(s)"
+        except getopt.GetoptError, e:
+                print "pkgsend: illegal open option '%s'" % e.opt
                 usage()
 
         eval_form = True
@@ -131,8 +131,8 @@
                                         abandon = True
                                 if opt == "-t":
                                         trans_id = arg
-        except:
-                print "pkgsend: illegal option(s) to close"
+        except getopt.GetoptError, e:
+                print "pkgsend: illegal option to close '%s'" % e.opt
                 usage()
 
         if trans_id == None:
@@ -243,8 +243,8 @@
         pargs = None
         try:
                 opts, pargs = getopt.getopt(sys.argv[1:], "s:R:")
-        except:
-                print "pkgsend: illegal global option(s)"
+        except getopt.GetoptError, e:
+                print "pkgsend: illegal global option '%s'" % e.opt
                 usage()
 
         if pargs == None or len(pargs) == 0: