[ooo-build-commit] scratch/mso-dumper

Kohei Yoshida kohei at kemper.freedesktop.org
Tue Dec 29 15:52:15 PST 2009


 scratch/mso-dumper/xls-dump.py |   53 +++++++++++++----------------------------
 1 file changed, 17 insertions(+), 36 deletions(-)

New commits:
commit b9765a52ca81cd980d9f66b283b035da8b41a466
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Tue Dec 29 18:51:11 2009 -0500

    [xls-dump] Switch from getopt to optparse to parse options and args.
    
    * scratch/mso-dumper/xls-dump.py:

diff --git a/scratch/mso-dumper/xls-dump.py b/scratch/mso-dumper/xls-dump.py
index 4dcee3f..4d63b81 100755
--- a/scratch/mso-dumper/xls-dump.py
+++ b/scratch/mso-dumper/xls-dump.py
@@ -1,21 +1,11 @@
 #!/usr/bin/env python
 
-import sys, os.path, getopt
+import sys, os.path, optparse
 sys.path.append(sys.path[0]+"/src")
 import ole, xlsstream, globals
 
 from globals import error
 
-def usage (exname):
-    exname = os.path.basename(exname)
-    msg = """Usage: %s [options] [xls file]
-
-Options:
-  --help        displays this help message.
-"""%exname
-    print msg
-
-
 class XLDumper(object):
 
     def __init__ (self, filepath, params):
@@ -75,35 +65,26 @@ class XLDumper(object):
             return False
 
 
-def main (args):
-    exname, args = args[0], args[1:]
-    if len(args) < 1:
-        print("takes at least one argument")
-        usage(exname)
-        return
-
+def main ():
+    parser = optparse.OptionParser()
+    parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False,
+        help="turn on debug mode")
+    parser.add_option("--show-sector-chain", action="store_true", dest="show_sector_chain", default=False,
+        help="show sector chain information at the start of the output.")
+    parser.add_option("--show-stream-pos", action="store_true", dest="show_stream_pos", default=False,
+        help="show the position of each record relative to the stream.")
+    options, args = parser.parse_args()
     params = globals.Params()
-    try:
-        opts, args = getopt.getopt(args, "h", ["help", "debug", "show-sector-chain"])
-        for opt, arg in opts:
-            if opt in ['-h', '--help']:
-                usage(exname)
-                return
-            elif opt in ['--debug']:
-                params.debug = True
-            elif opt in ['--show-sector-chain']:
-                params.showSectorChain = True
-            else:
-                error("unknown option %s\n"%opt)
-                usage()
-
-    except getopt.GetoptError:
-        error("error parsing input options\n")
-        usage(exname)
+    params.debug = options.debug
+    params.showSectorChain = options.show_sector_chain
+    params.showStreamPos = options.show_stream_pos
+    if len(args) < 1:
+        globals.error("takes at least one argument\n")
+        parser.print_help()
         return
 
     dumper = XLDumper(args[0], params)
     dumper.dump()
 
 if __name__ == '__main__':
-    main(sys.argv)
+    main()


More information about the ooo-build-commit mailing list