-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlanetProfileCLI.py
51 lines (48 loc) · 1.98 KB
/
PlanetProfileCLI.py
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
import os, sys, numpy as np
from PlanetProfile.Main import run
if __name__ == '__main__':
# Command line args
nArgs = len(sys.argv)
clArg = None
fNames = None
if nArgs > 1 and ('PP' not in sys.argv[1] and '.txt' not in sys.argv[1]):
# Body name was passed as command line argument
bodyname = sys.argv[1]
# Additional command line arguments
if nArgs > 2:
if 'PP' in sys.argv[2]:
print('PP in CL arg 2 -- interpreting as (list of) filename(s).')
fNames = sys.argv[2:]
elif '.txt' in sys.argv[2]:
print('.txt in CL arg 2 -- interpreting as (list of) filename(s) to reload.')
fNames = sys.argv[2:]
clArg = 'reload'
else:
clArg = sys.argv[2]
if nArgs > 3:
if 'PP' in sys.argv[3]:
fNames = sys.argv[3:]
else:
print(f'Too many command line args passed. Ignoring command "{sys.argv[3]}" and any after it.')
elif 'PP' in sys.argv[1]:
print('PP in first CL arg -- interpreting as (list of) filename(s).')
fNames = sys.argv[1:]
if len(fNames) == 1:
bodyname = os.path.split(fNames[0])[0]
fNames = os.path.split(fNames[0])[1:]
else:
bodynames = [os.path.split(fName)[0] for fName in fNames]
if np.all(bodynames == bodynames[0]):
bodyname = bodynames[0]
fNames = [os.path.split(fName)[1] for fName in fNames]
else:
bodyname = ''
elif '.txt' in sys.argv[1]:
print('.txt in first CL arg -- interpreting as (list of) filename(s) to reload.')
fNames = sys.argv[1:]
bodyname = ''
clArg = 'reload'
else:
# No command line argument, ask user which body to run
bodyname = input('Please input body name: ')
run(bodyname=bodyname, opt=clArg, fNames=fNames)