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 Uncategorized utility routines for roslaunch.
35
36 This API should not be considered stable.
37 """
38
39 from __future__ import print_function
40
41 import os
42 import sys
43 import time
44
45 import roslib.packages
46
47 import rosclean
48 import rospkg
49 import rosgraph
50
51 import roslaunch.core
52 import roslaunch.config
53 import roslaunch.depends
54 from rosmaster import DEFAULT_MASTER_PORT
55
57 """
58 Check size of log directory. If high, print warning to user
59 """
60 try:
61 d = rospkg.get_log_dir()
62 roslaunch.core.printlog("Checking log directory for disk usage. This may take awhile.\nPress Ctrl-C to interrupt")
63 disk_usage = rosclean.get_disk_usage(d)
64
65 if disk_usage > 1073741824:
66 roslaunch.core.printerrlog("WARNING: disk usage in log directory [%s] is over 1GB.\nIt's recommended that you use the 'rosclean' command."%d)
67 else:
68 roslaunch.core.printlog("Done checking log file disk usage. Usage is <1GB.")
69 except:
70 pass
71
73 """
74 Resolve command-line args to roslaunch filenames.
75
76 :returns: resolved filenames, ``[str]``
77 """
78
79
80 args = rosgraph.myargv(args)
81
82
83
84
85 if not args:
86 return args
87 resolved_args = None
88
89
90 if len(args) >= 2:
91 try:
92 resolved = roslib.packages.find_resource(args[0], args[1])
93 if len(resolved) > 1:
94 raise roslaunch.core.RLException("multiple files named [%s] in package [%s]:%s\nPlease specify full path instead" % (args[1], args[0], ''.join(['\n- %s' % r for r in resolved])))
95 if len(resolved) == 1:
96 resolved_args = [resolved[0]] + args[2:]
97 except rospkg.ResourceNotFound:
98 pass
99
100 if resolved_args is None and os.path.isfile(args[0]):
101 resolved_args = [args[0]] + args[1:]
102
103 if resolved_args is None:
104 if len(args) >= 2:
105 raise roslaunch.core.RLException("[%s] is neither a launch file in package [%s] nor is [%s] a launch file name" % (args[1], args[0], args[0]))
106 else:
107 raise roslaunch.core.RLException("[%s] is not a launch file name" % args[0])
108 return resolved_args
109
127
128 _terminal_name = None
129
131 import platform
132 if platform.system() in ['FreeBSD', 'Linux', 'Darwin', 'Unix']:
133 try:
134 print('\033]2;%s\007'%(s))
135 except:
136 pass
137
144
152
154 """
155 :param options_runid: run_id value from command-line or ``None``, ``str``
156 :param options_wait_for_master: the wait_for_master command
157 option. If this is True, it means that we must retrieve the
158 value from the parameter server and need to avoid any race
159 conditions with the roscore being initialized. ``bool``
160 """
161
162
163
164
165
166
167 if options_runid:
168 return options_runid
169
170
171
172
173 param_server = rosgraph.Master('/roslaunch')
174 val = None
175 while val is None:
176 try:
177 val = param_server.getParam('/run_id')
178 except:
179 if not options_wait_for_master:
180 val = roslaunch.core.generate_run_id()
181 return val
182
184 """
185 Check roslaunch file for errors, returning error message if check fails. This routine
186 is mainly to support rostest's roslaunch_check.
187
188 :param f: roslaunch file name, ``str``
189 :returns: error message or ``None``
190 """
191 try:
192 rl_config = roslaunch.config.load_config_default([f], DEFAULT_MASTER_PORT, verbose=False)
193 except roslaunch.core.RLException as e:
194 return str(e)
195
196 errors = []
197
198 try:
199 base_pkg, file_deps, missing = roslaunch.depends.roslaunch_deps([f])
200 except rospkg.common.ResourceNotFound as r:
201 errors.append("Could not find package [%s] included from [%s]"%(str(r), f))
202 missing = {}
203 file_deps = {}
204 except roslaunch.substitution_args.ArgException as e:
205 errors.append("Could not resolve arg [%s] in [%s]"%(str(e), f))
206 missing = {}
207 file_deps = {}
208 for pkg, miss in missing.iteritems():
209 if miss:
210 errors.append("Missing manifest dependencies: %s/manifest.xml: %s"%(pkg, ', '.join(miss)))
211
212
213 nodes = []
214 for filename, rldeps in file_deps.iteritems():
215 nodes.extend(rldeps.nodes)
216
217
218 rospack = rospkg.RosPack()
219 for pkg, node_type in nodes:
220 try:
221 rospack.get_path(pkg)
222 except:
223 errors.append("cannot find package [%s] for node [%s]"%(pkg, node_type))
224
225
226 for pkg, node_type in nodes:
227 try:
228 if not roslib.packages.find_node(pkg, node_type):
229 errors.append("cannot find node [%s] in package [%s]"%(node_type, pkg))
230 except Exception as e:
231 errors.append("unable to find node [%s/%s]: %s"%(pkg, node_type, str(e)))
232
233
234 for err in rl_config.config_errors:
235 errors.append('ROSLaunch config error: %s' % err)
236
237 if errors:
238 return '\n'.join(errors)
239
256