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 Uncategorized utility routines for roslaunch.
37
38 This API should not be considered stable.
39 """
40
41 import os
42 import time
43
44 from roslib.names import SEP
45
46 import roslaunch.core
47 from rosmaster import DEFAULT_MASTER_PORT
48
50 """
51 Check size of log directory. If high, print warning to user
52 """
53 try:
54 import rosclean
55 import roslib.rosenv
56 d = roslib.rosenv.get_log_dir()
57 roslaunch.core.printlog("Checking log directory for disk usage. This may take awhile.\nPress Ctrl-C to interrupt")
58 disk_usage = rosclean.get_disk_usage(d)
59
60 if disk_usage > 1073741824:
61 roslaunch.core.printerrlog("WARNING: disk usage in log directory [%s] is over 1GB.\nIt's recommended that you use the 'rosclean' command."%d)
62 else:
63 roslaunch.core.printlog("Done checking log file disk usage. Usage is <1GB.")
64 except:
65 pass
66
68 """
69 Resolve command-line args to roslaunch filenames.
70 @return: resolved filenames
71 @rtype: [str]
72 """
73 import roslib.packages
74 import roslib.scriptutil
75
76
77 args = roslib.scriptutil.myargv(args)
78
79
80
81
82 if not args:
83 return args
84 resolved_args = None
85 top = args[0]
86 if os.path.isfile(top):
87 resolved_args = [top] + args[1:]
88 elif len(args) == 1:
89 raise roslaunch.core.RLException("[%s] does not exist. please specify a package and launch file"%(top))
90 else:
91 try:
92 resolved = roslib.packages.find_resource(top, args[1])
93 if len(resolved) == 1:
94 resolved = resolved[0]
95 elif len(resolved) > 1:
96 raise roslaunch.core.RLException("multiple files named [%s] in package [%s].\nPlease specify full path instead"%(args[1], top))
97 except roslib.packages.InvalidROSPkgException, e:
98 raise roslaunch.core.RLException("[%s] is not a package or launch file name"%top)
99 if not resolved:
100 raise roslaunch.core.RLException("cannot locate [%s] in package [%s]"%(args[1], top))
101 else:
102 resolved_args = [resolved] + args[2:]
103 return resolved_args
104
122
123 _terminal_name = None
124
126 import platform
127 if platform.system() in ['FreeBSD', 'Linux', 'Darwin', 'Unix']:
128 try:
129 print '\033]2;%s\007'%(s)
130 except:
131 pass
132
139
147
149 """
150 @param options_runid: run_id value from command-line or None
151 @type options_runid: str
152 @param options_wait_for_master: the wait_for_master command
153 option. If this is True, it means that we must retrieve the
154 value from the parameter server and need to avoid any race
155 conditions with the roscore being initialized.
156 @type options_wait_for_master: bool
157 """
158 import roslib.scriptutil
159
160
161
162
163
164 if options_runid:
165 return options_runid
166
167
168
169
170 param_server = roslib.scriptutil.get_param_server()
171 val = None
172 while val is None:
173 try:
174 code, msg, val = param_server.getParam('/roslaunch', '/run_id')
175 if code == 1:
176 return val
177 else:
178 val = None
179 raise RuntimeError("unknown error communicating with Parameter Server: %s"%msg)
180 except:
181 if not options_wait_for_master:
182 val = roslaunch.core.generate_run_id()
183 return val
184
186 """
187 Check roslaunch file for errors, returning error message if check fails. This routine
188 is mainly to support rostest's roslaunch_check.
189
190 @param f: roslaunch file name
191 @type f: str
192 @return: error message or None
193 @rtype: str
194 """
195 try:
196 import roslaunch.config
197 config = roslaunch.config.load_config_default([f], DEFAULT_MASTER_PORT, verbose=False)
198 except roslaunch.RLException, e:
199 return str(e)
200
201 errors = []
202
203 import roslaunch.depends
204 base_pkg, file_deps, missing = roslaunch.depends.roslaunch_deps([f])
205 for pkg, miss in missing.iteritems():
206 if miss:
207 errors.append("Missing manifest dependencies: %s/manifest.xml: %s"%(pkg, ', '.join(miss)))
208
209
210 nodes = []
211 for filename, rldeps in file_deps.iteritems():
212 nodes.extend(rldeps.nodes)
213
214
215 import roslib.packages
216 for pkg, node_type in nodes:
217 try:
218 roslib.packages.get_pkg_dir(pkg, required=True)
219 except:
220 errors.append("cannot find package [%s] for node [%s]"%(pkg, node_type))
221
222
223 for pkg, node_type in nodes:
224 try:
225 if not roslib.packages.find_node(pkg, node_type):
226 errors.append("cannot find node [%s] in package [%s]"%(node_type, pkg))
227 except Exception, e:
228 errors.append("unable to find node [%s/%s]: %s"%(pkg, node_type, str(e)))
229
230
231 for err in config.config_errors:
232 errors.append('ROSLaunch config error: %s' % err)
233
234 if errors:
235 return '\n'.join(errors)
236
237
239 if name is None:
240 raise ValueError('name')
241 if not isinstance(name, basestring):
242 raise TypeError('name')
243 if not name:
244 return [SEP]
245
246 splits = [x for x in name.split(SEP) if x]
247 return ['/'] + ['/'+SEP.join(splits[:i]) for i in xrange(1, len(splits))]
248