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