-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.py
executable file
·87 lines (76 loc) · 2.46 KB
/
run.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
#!/usr/bin/python
import subprocess
import time
import getopt
import sys
import atexit
import generateEntity
import generateWorldFile
processes = []
"""
@function
This script is responsible to execute the generate scripts and starts roscore,
stage_ros and all the entities
"""
def main(argv):
testing = False
debugging = False
webservice = False
# Loads the config properties and passes the dictionary to the generate scripts
config = {}
with open("config.properties", "r") as f:
for line in f:
property = line.split('=')
config[property[0]] = property[1]
# Checks if any arguments has been given
try:
opts, args = getopt.getopt(argv,"dtw")
except getopt.GetoptError:
print 'run.py -d for debugger mode '
print 'run.py -t for testing mode '
print 'run.py -w for webservice mode '
sys.exit(2)
for opt, arg in opts:
if opt == "-t":
testing = True
elif opt == "-d":
debugging = True
elif opt == "-w":
webservice = True
if testing:
list = generateEntity.main(['-t'], config)
generateWorldFile.main(config)
return list
else:
if debugging:
list = generateEntity.main(["-d"])
else:
list = generateEntity.main([""], config)
atexit.register(generateEntity.exit_process, list)
generateWorldFile.main(config)
processes.append(subprocess.Popen(["roscore"], shell=False))
processes.append(subprocess.Popen(["rosrun", "stage_ros", "stageros", "world/myworld.world"], shell=False))
time.sleep(5)
atexit.register(kill_process)
# Executes GUI script
processes.append(subprocess.Popen(['python', 'GUI_overlay.py'], cwd=r'./se306Project1/src'))
atexit.register(delete_guifiles)
if webservice:
processes.append(subprocess.Popen(['python', 'Webservice.py'], cwd=r'./se306Project1/src'))
while True:
pass
"""
@function
This function is called to delete all the sta files generated by the GUI
"""
def delete_guifiles():
subprocess.Popen(['python', '-c', 'import GUI_overlay; GUI_overlay.delete_files()'], cwd=r'./se306Project1/src')
"""
@function
This function is called to end all the processes executed in this script
"""
def kill_process():
for i in range(0, processes.__len__()):
processes[i].terminate()
if __name__ == "__main__":
main(sys.argv[1:])