forked from damonwang/xraylarch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
larch
executable file
·116 lines (90 loc) · 3.52 KB
/
larch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python
"""Larch program -- interactive command-line interface.
This will use wx graphics device, if available.
Usage: larch [option] files(s)
with options
--version show version number and exit
-h, --help show help message and exit
-q, --quiet set quiet mode
-d, --debug set debug mode
-x, --nowx set no wx graphics mode
-e, --exec execute script from file(s) only
# -r, --remote run in remote server mode (not yet implemented)
# -p PORT, --port=PORT port number for remote server
"""
import sys
import numpy
from optparse import OptionParser
__extra__ = ''
usage = "usage: %prog [options] file(s)"
parser = OptionParser(usage=usage, prog="larch",
version="larch command-line version 0.2")
parser.add_option("-q", "--quiet", dest="quiet", action="store_true",
default=False, help="set quiet mode, default = False")
parser.add_option("-d", "--debug", dest="debug", action="store_true",
default=False, help="set debug mode, default = False")
parser.add_option("-x", "--nowx", dest="nowx", action="store_true",
default=False, help="set no wx graphics mode, default = False")
parser.add_option("-e", "--exec", dest="noshell", action="store_true",
default=False, help="execute script only, default = False")
parser.add_option("-r", "--remote", dest="server_mode", action="store_true",
default=False, help="run in remote server mode")
parser.add_option("-p", "--port", dest="port", default='7239',
metavar='PORT', help="port number for remote server")
(options, args) = parser.parse_args()
if options.server_mode:
print 'Warning: remote server mode not working!'
if options.debug:
try:
import lib as larch
__extra__ = '%s\n ===> DEBUG, using lib as larch <===' % __extra__
except ImportError:
import larch
else:
import larch
# can we, and should we, use wx?
HAS_WX = False
if not options.nowx:
try:
import wx
HAS_WX = True
except ImportError:
HAS_WX = False
BANNER = """ Larch %s (%s) M. Newville, T. Trainor
using python %s, numpy %s""" % (larch.__version__, larch.__date__,
'%i.%i.%i' % sys.version_info[:3],
numpy.__version__)
if HAS_WX:
BANNER = "%s, wx-enabled, wx version %s" % (BANNER, wx.__version__)
else:
BANNER = "%s, NO wx graphics!" % BANNER
if len(__extra__) > 0:
BANNER = "%s %s" % (BANNER, __extra__)
shell = larch.shell(banner_msg=BANNER, quiet=options.quiet)
def onCtrlC(*args, **kws):
return 0
# use inputhook to enable wx
if HAS_WX:
if options.debug:
from lib.wx import inputhook
else:
from larch.wx import inputhook
app = wx.App(redirect=False, clearSigInt=False)
shell.larch.add_plugin('wx', wxparent=None)
inputhook.ON_INTERRUPT = onCtrlC
# execute scripts listed on command-line
if len(args)>0:
for arg in args:
if arg.endswith('.py'):
shell.default("import %s" % arg[:-3])
else:
shell.input.interactive = False
finp = open(arg, 'r')
for itxt, txt in enumerate(finp.readlines()):
shell.input.put(txt[:-1], lineno=itxt, filename=arg)
finp.close()
shell.larch_execute('')
shell.input.interactive = True
# if interactive, start command loop
if not options.noshell:
shell.cmdloop()