-
Notifications
You must be signed in to change notification settings - Fork 9
/
scenario_loader.py
99 lines (80 loc) · 3.33 KB
/
scenario_loader.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
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
#!/usr/bin/env python
# Copyright (c) 2018 Christoph Pilz
#
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.
import inspect
import os
import prctl
import sys
from test_control import TestControl
CMDLINEPARAM_PROGNAME = 0
CMDLINEPARAM_PROGMODE = 1
CMDLINEPARAM_SIMTYPE = 1
CMDLINEPARAM_SIMIP = 2
CMDLINEPARAM_SIMPORT = 3
CMDLINEPARAM_SIMTIMEOUT = 4
CMDLINEPARAM_SCENARIOFORMAT = 5
CMDLINEPARAM_SCENARIOFILES_START = 6
def main():
if len(sys.argv) == 2:
if sys.argv[CMDLINEPARAM_PROGMODE] == "help":
print(inspect.getfile(inspect.currentframe()) + " help - get this message")
print(inspect.getfile(inspect.currentframe()) +
" <Carla> <OpenScenario> <OpenScenario-file> - for standard execution")
exit()
else:
print("[Error] Wrong command line parameters, try: \"" +
inspect.getfile(inspect.currentframe()) + " help\"")
exit()
# TODO implement multi scenario
elif len(sys.argv) > CMDLINEPARAM_SCENARIOFILES_START:
# load params
simType = sys.argv[CMDLINEPARAM_SIMTYPE]
simIP = sys.argv[CMDLINEPARAM_SIMIP]
simPort = int(sys.argv[CMDLINEPARAM_SIMPORT])
simTimeout = float(sys.argv[CMDLINEPARAM_SIMTIMEOUT])
scenarioFormat = sys.argv[CMDLINEPARAM_SCENARIOFORMAT]
scenarioFiles = getFileNames()
if len(scenarioFiles) == 0:
print("[Error] parameter", CMDLINEPARAM_SCENARIOFILES_START, "-", len(sys.argv), "have to contain valid paths to files")
exit()
for scenarioFile in scenarioFiles:
print("## Loading Scenario:", scenarioFile)
# create TestControl class
testControl = TestControl(simType, simIP, simPort, simTimeout, scenarioFormat)
# try loading scenario-config
if not testControl.setupTestWithConfig(scenarioFile):
print("[Error] TestControl-Setup failed for", scenarioFile)
# TODO save log?
continue
testControl.executeTest()
# Simulation is built up
# Simulation is executed
testControl.cleanupTest()
if testControl.isSkipCurrentTest:
print("## Scenario:", scenarioFile, "skipped.")
continue
elif testControl.isAbortAllFurtherTests:
print("## Scenario:", scenarioFile, "and all further scenarios aborted")
break
print("##Finished Scenario:", scenarioFile)
print(" --- The End ---")
else:
print("[Error] try \"" + inspect.getfile(inspect.currentframe()) + " help\"")
def getFileNames():
scenarioFiles = []
for i in range(CMDLINEPARAM_SCENARIOFILES_START, len(sys.argv)):
if os.path.isfile(sys.argv[i]):
scenarioFiles.append(sys.argv[i])
elif os.path.isdir(sys.argv[i]):
for root, subdirs, files in os.walk(sys.argv[i]):
for filename in files:
file_path = os.path.join(root, filename)
scenarioFiles.append(os.path.join(root, filename))
else:
print("[Info][main::getFileNames] Hmm wierd ... what did we find?")
return scenarioFiles
if __name__ == '__main__':
prctl.set_name("init")
main()