Add test/get_curve.py
[hooke.git] / hooke / hooke.py
index c2ef159d8bccc4bbbfe5ac5b789ad52ae55132f1..54f0f0fb695b7ec734f0ee91ff7d5d526b5d8f78 100644 (file)
@@ -64,12 +64,13 @@ import unittest
 import StringIO
 import sys
 
-from . import engine as engine
+from . import version
+from . import engine
 from . import config as config_mod
-from . import playlist as playlist
+from . import playlist
 from . import plugin as plugin_mod
 from . import driver as driver_mod
-from . import ui as ui
+from . import ui
 
 
 class Hooke (object):
@@ -171,6 +172,9 @@ class HookeRunner (object):
 
 def main():
     p = optparse.OptionParser()
+    p.add_option(
+        '--version', dest='version', default=False, action='store_true',
+        help="Print Hooke's version information and exit.")
     p.add_option(
         '-s', '--script', dest='script', metavar='FILE',
         help='Script of command line Hooke commands to run.')
@@ -178,6 +182,10 @@ def main():
         '-c', '--command', dest='commands', metavar='COMMAND',
         action='append', default=[],
         help='Add a command line Hooke command to run.')
+    p.add_option(
+        '--command-no-exit', dest='command_exit',
+        action='store_false', default=True,
+        help="Don't exit after running a script or commands.")
     options,arguments = p.parse_args()
     if len(arguments) > 0:
         print >> sys.stderr, 'More than 0 arguments to %s: %s' \
@@ -188,16 +196,19 @@ def main():
     hooke = Hooke(debug=__debug__)
     runner = HookeRunner()
 
+    if options.version == True:
+        print version()
+        sys.exit(0)
     if options.script != None:
-        f = open(os.path.expanduser(options.script), 'r')
-        options.commands.extend(f.readlines())
-        f.close
+        with open(os.path.expanduser(options.script), 'r') as f:
+            options.commands.extend(f.readlines())
     if len(options.commands) > 0:
         try:
             hooke = runner.run_lines(hooke, options.commands)
         finally:
-            hooke.close()
-        sys.exit(0)
+            if options.command_exit == True:
+                hooke.close()
+                sys.exit(0)
 
     try:
         hooke = runner.run(hooke)