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 a while.\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 (args[0] == '-' or 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 :param use_test_depends: Consider test_depends, ``Bool``
190 :param ignore_unset_args: Consider ignore default arg requirements, ``Bool``
191 :returns: error message or ``None``
192 """
193 try:
194 rl_config = roslaunch.config.load_config_default([f], DEFAULT_MASTER_PORT, verbose=False, ignore_unset_args=ignore_unset_args)
195 except roslaunch.core.RLException as e:
196 return str(e)
197
198 rospack = rospkg.RosPack()
199 errors = []
200
201 try:
202 base_pkg, file_deps, missing = roslaunch.depends.roslaunch_deps([f], use_test_depends=use_test_depends, ignore_unset_args=ignore_unset_args)
203 except rospkg.common.ResourceNotFound as r:
204 errors.append("Could not find package [%s] included from [%s]"%(str(r), f))
205 missing = {}
206 file_deps = {}
207 except roslaunch.substitution_args.ArgException as e:
208 errors.append("Could not resolve arg [%s] in [%s]"%(str(e), f))
209 missing = {}
210 file_deps = {}
211 for pkg, miss in missing.items():
212
213 all_pkgs = []
214 try:
215 for file_dep in file_deps.keys():
216 file_pkg = rospkg.get_package_name(file_dep)
217 all_pkgs.extend(rospack.get_depends(file_pkg,implicit=False))
218 miss_all = list(set(miss) - set(all_pkgs))
219 except Exception as e:
220 print(e, file=sys.stderr)
221 miss_all = True
222 if miss_all:
223 roslaunch.core.printerrlog("Missing package dependencies: %s/package.xml: %s"%(pkg, ', '.join(miss)))
224 errors.append("Missing package dependencies: %s/package.xml: %s"%(pkg, ', '.join(miss)))
225 elif miss:
226 roslaunch.core.printerrlog("Missing package dependencies: %s/package.xml: %s (notify upstream maintainer)"%(pkg, ', '.join(miss)))
227
228
229 nodes = []
230 for filename, rldeps in file_deps.items():
231 nodes.extend(rldeps.nodes)
232
233
234 for pkg, node_type in nodes:
235 try:
236 rospack.get_path(pkg)
237 except:
238 errors.append("cannot find package [%s] for node [%s]"%(pkg, node_type))
239
240
241 for pkg, node_type in nodes:
242 try:
243 if not roslib.packages.find_node(pkg, node_type, rospack=rospack):
244 errors.append("cannot find node [%s] in package [%s]"%(node_type, pkg))
245 except Exception as e:
246 errors.append("unable to find node [%s/%s]: %s"%(pkg, node_type, str(e)))
247
248
249 for err in rl_config.config_errors:
250 errors.append('ROSLaunch config error: %s' % err)
251
252 if errors:
253 return '\n'.join(errors)
254
271