Commits

anatoly techtonik committed 845816d

support execution from command line

Comments (0)

Files changed (2)

     ...
     xtrace.stop()
 
+It is also possible to call `xtrace` as module from the command line::
+
+    python -m xtrace <script.py> [param] ...
+
+or use as a standalone script::
+
+    python xtrace.py <script.py> [param] ...
+
+
 The output format is that of Xdebug http://xdebug.org/docs/execution_trace
 But frankly, I didn't have time to polish it to be exactly the same. If you
 will find the time and desire to polish it - feel free to send a patch.
         pass #print 'TRACE: UNKNOWN %s EVENT WITH ARG %s' % (event, arg)
         return
 
+
+def main():
+    if not sys.argv[1:] or sys.argv[1] in ['-h', '--help']:
+        # [ ] detect when run as a module
+        sys.exit("Usage: %s <script.py> [param] ..." % sys.argv[0])
+    
+    script = sys.argv[1]
+    # strip xtrace from sys.argv
+    sys.argv = sys.argv[1:]
+    
+    start()
+    execfile(script)
+    stop()
+
+if __name__ == '__main__':
+    main()
+