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