-
Notifications
You must be signed in to change notification settings - Fork 0
/
rosmetalaunch
executable file
·83 lines (70 loc) · 2.29 KB
/
rosmetalaunch
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
#!/usr/bin/python
import os
import sys
import stat
import time
import argparse
import subprocess
import xml.dom.minidom
LAUNCH_DELAY = 5
def get_description(file):
dom = xml.dom.minidom.parse(file)
description = dom.getElementsByTagName("description")[0]
brief = description.getAttribute("brief")
dom.unlink()
return brief
def launcher(file):
try:
pid = os.fork()
if pid > 0:
return
except Exception, e:
print e, ": Initial fork"
sys.exit(os.EX_OSERR)
output_log = open("/tmp/%s.log"%os.path.basename(file), "a+")
error_log = open("/tmp/%s.log"%os.path.basename(file), "a+", 0)
null_input = open("/dev/null", "r")
os.dup2(null_input.fileno(), sys.stdin.fileno())
os.dup2(output_log.fileno(), sys.stdout.fileno())
os.dup2(error_log.fileno(), sys.stderr.fileno())
try:
pid = os.fork()
if pid > 0:
sys.exit(os.EX_OK)
except Exception, e:
print e, ": Secondary fork"
sys.exit(os.EX_OSERR)
os.setsid()
os.umask(stat.S_IWOTH)
launch_dir = os.path.dirname(file)
if launch_dir:
os.chdir(launch_dir)
try:
pid = os.fork()
if pid > 0:
# log PID here
sys.exit(os.EX_OK)
except Exception, e:
print e, ": Tertiary fork"
sys.exit(os.EX_OSERR)
info = get_description(file)
p = subprocess.Popen("DISPLAY=:0 /usr/bin/notify-send --icon=ros-tool --category='network.connected' 'ROS Launch' '%s'"%info, stdout=subprocess.PIPE, shell=True)
p.wait()
p = subprocess.Popen("roslaunch %s"%file, stdout=subprocess.PIPE, shell=True)
p.wait()
sys.exit(os.EX_OK)
def islaunchfile(file): return file.endswith(".launch")
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='rosmetalaunch',
epilog='ROS MetaLaunch Tool')
parser.add_argument('launch_path', help='Launch Directory')
args = parser.parse_args()
try:
files = os.listdir(args.launch_path)
except Exception, e:
print e, ": Invalid launch directory"
sys.exit(os.EX_OSFILE)
launchfiles = sorted(filter(islaunchfile, files))
for file in launchfiles[:]:
launcher("%s/%s"%(args.launch_path,file))
time.sleep(LAUNCH_DELAY)