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