source: SHX/trunk/SeismicHandler/bin/SH @ 529

Revision 529, 1.3 KB checked in by marcus, 11 years ago (diff)
  • accept tailing comment within command line
  • access to trace info entries
  • Property svn:executable set to *
Line 
1#! /usr/bin/env python
2
3"""
4Helper script for executing SH scripts and interactive usage.
5"""
6
7import os
8import sys
9from StringIO import StringIO
10try:
11    import readline
12except:
13    # readline module is not available on Windows OS
14    pass
15from SeismicHandler.modules.parse import Script, Symbol, Switches
16from SeismicHandler.basics.error import ShxError
17from SeismicHandler.config import Settings
18from SeismicHandler.basics.codes import LICENCE, VERSION
19
20
21def run(filename):
22    path, script = os.path.split(filename)
23
24    # add path information
25    if path:
26        s = Script(open(sys.argv[1]), Symbol(), Switches(), searchpath=[path])
27    else:
28        s = Script(open(sys.argv[1]), Symbol(), Switches())
29
30    s.run()
31
32
33def interactive():
34    s = Script(StringIO(""), Symbol(), Switches())
35    while True:
36        try:
37            inp = raw_input("|shx> ")
38        except (EOFError, KeyboardInterrupt):
39            quit()
40
41        s.feed(StringIO(inp + os.linesep))
42        try:
43            s.run()
44        except ShxError:
45            if Settings.swSherrstop:
46                quit(1)
47        except NotImplementedError:
48            print "Command currently not available!"
49
50
51if __name__ == "__main__":
52    if len(sys.argv) > 1:
53        run(sys.argv[1])
54    else:
55        print LICENCE % VERSION
56        interactive()
Note: See TracBrowser for help on using the repository browser.