small cleanup

Mon, 10 Dec 2007 21:22:33 +0100

author
David Douard <david.douard@logilab.fr>
date
Mon, 10 Dec 2007 21:22:33 +0100
changeset 4
269aacbb2bf2
parent 3
e2587668ec72
child 5
4d86b11abb82

small cleanup

dump_trace.py file | annotate | diff | comparison | revisions
--- a/dump_trace.py	Mon Dec 10 21:19:33 2007 +0100
+++ b/dump_trace.py	Mon Dec 10 21:22:33 2007 +0100
@@ -1,5 +1,6 @@
 import sys
 import time
+import gpib
 
 MODE = {'binary': 'DDBN',
         'ascii': 'DDAS',
@@ -25,32 +26,32 @@
     return res
 
 
+if __name__=='__main__':
+    import optparse
+    opt = optparse.OptionParser("A simple tool for dumping the current trace")
+    opt.add_option('-f', '--filename', default=None,
+                   dest='filename',
+                   help='Output filename. If not set, write to stdout')
+    opt.add_option('-d', '--device', default='/dev/ttyUSB0',
+                   dest='device',
+                   help='Device of the RS232 connection (default: /dev/ttyUSB0)',
+                   )
+    opt.add_option('-m', '--mode', default='binary',
+                   dest='mode',
+                   help='Dumping mode (may be "binary" [default], "ascii" or "ansi")',
+                   )
+    opt.add_option('-a', '--address', default=0,
+                   dest='address',
+                   help='GPIB address of the device',
+                   )
+    options, argv = opt.parse_args(sys.argv)
 
-import optparse
-opt = optparse.OptionParser()
-opt.add_option('-f', '--filename', default=None,
-               dest='filename',
-               help='Output filename. If not set, write to stdout')
-opt.add_option('-d', '--device', default='/dev/ttyUSB0',
-               dest='device',
-               help='Device of the RS232 connection (default: /dev/ttyUSB0)',
-               )
-opt.add_option('-m', '--mode', default='binary',
-               dest='mode',
-               help='Dumping mode (may be "binary" [default], "ascii" or "ansi")',
-               )
-opt.add_option('-a', '--address', default=0,
-               dest='address',
-               help='GPIB address of the device',
-               )
-options, argv = opt.parse_args(sys.argv)
+    cnx = open_connection(device=options.device,
+                          address=int(options.address), mode=1)
+    res = read_trace(cnx, mode=options.mode)
 
-cnx = open_connection(device=options.device,
-                      address=int(options.address), mode=1)
-res = read_trace(cnx, mode=options.mode)
-
-if options.filename:
-    open(options.filename, 'w').write(res)
-else:
-    print res
+    if options.filename:
+        open(options.filename, 'w').write(res)
+    else:
+        print res
     

mercurial