-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathexosims-run
executable file
·94 lines (83 loc) · 2.68 KB
/
exosims-run
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
#!/usr/bin/env python
#
# EXOSIMS driver
r"""EXOSIMS driver script: run the simulation with the given parameters.
Usage:
exosims-run [-h] [-v] [-j JSON_LITERAL] scriptfile
where:
scriptfile
a text file containing a JSON literal to instantiate
the EXOSIMS parameters
-j JSON_LITERAL
contains a literal JSON string augmenting or over-riding
the scriptfile parameters, e.g.: {"seed":123454321} to
set the random number generator initial seed.
-h
print usage help and exit
-v
verbosity
To enter the debugger, use:
python -m pdb exosims-run scriptfile
You will stop within pdb at the first line of code. Type c to continue
from that point. If an exception is raised, you will return to the
debugger.
"""
import sys
import json
import getopt
import os.path
import EXOSIMS
import EXOSIMS.MissionSim
def main(name, argv):
r"""Instantiate and run an EXOSIMS MissionSim object.
Args:
name (string):
program name (argv[0]) as invoked
argv (list of string)
remaining options and arguments
Returns:
(nothing)
"""
def usage():
sys.stderr.write("Usage: %s [-h] [-v] [-j JSON_LITERAL] scriptfile\n" % name)
try:
opts, args = getopt.getopt(argv, "hvj:", ["help", "verbose", "json="])
except getopt.GetoptError:
usage()
sys.exit(2)
json_string = None
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit(0)
elif opt in ('-v', '--verbose'):
# this mechanism is TBD
global _verbose
_verbose = 1
elif opt in ("-j", "--json"):
# explicit
json_string = arg
# the script file is the remaining arg
if len(args) is 0:
# scriptfile = None
sys.stderr.write('Error: scriptfile is required.\n')
usage()
sys.exit(1)
elif len(args) is 1:
scriptfile = args[0]
else:
usage()
sys.exit(1)
# process the literal json string, if any
if json_string:
specs = json.loads(json_string)
else:
specs = {}
sim = EXOSIMS.MissionSim.MissionSim(scriptfile, **specs)
result = sim.SurveySimulation.run_sim()
# TODO: exit with proper status code
sys.exit(0)
# boilerplate to allow running from the command-line
if __name__ == '__main__':
# arg 1 is name as run, arg 2 is remaining args, if any
main(os.path.basename(sys.argv[0]), sys.argv[1:])