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

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