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 from __future__ import with_statement
36
37 import os
38 import stat
39 import sys
40
41 import roslib.manifest
42 import roslib.packages
43 import roslib.stack_manifest
44 import roslib.stacks
45
46
47 from rosh.impl.namespace import Namespace, Concept, ResourceList
48
49 from rosh.impl.msg import Msgs
50
52
54 """
55 ctor.
56 @param config: Namespace configuration instance with additional 'listener' attribute.
57 @type config: L{NamespaceConfig}
58 """
59 self.name = name
60
61
62
63
64 if not name:
65 return
66 self._config = config
67
68 self.path = self._get_path()
69 self.manifest = self._get_manifest(self.path)
70
73
76
78
79
80 return ResourceList(self._config, [str(x) for x in self.manifest.depends], self.__class__)
81
82 depends1 = property(_get_depends1)
83
86
89
92 self.__dict__.update(d)
93
97
99 return roslib.packages.get_pkg_dir(self.name)
100
102 return roslib.manifest.parse_file(os.path.join(path, roslib.manifest.MANIFEST_FILE))
103
105 try:
106
107 if self.name in self._config.ctx.msg:
108
109 return self._config.ctx.msg[self.name]
110 except AttributeError:
111
112 pass
113 return None
114
116 try:
117
118 if self.name in self._config.ctx.srv:
119
120 return self._config.ctx.srv[self.name]
121 except AttributeError:
122
123 pass
124 return None
125
126
127
133
139
140
141 msg = property(_get_msgs)
142 srv = property(_get_srvs)
143 nodes = property(_get_nodes)
144 launches = property(_get_launches)
145
147 return k.replace('.', '_')
148
149 try:
150 import roslaunch
151 except ImportError:
152 print >> sys.stderr, "cannot import roslaunch, launching is disabled"
155 raise Exception("cannot import roslaunch, launching is disabled")
156 roslaunch = FakeLaunch()
157
159 - def __init__(self, ctx, package, type_):
160 self.ctx = ctx
161 self.package = package
162 self.type = type_
166
168 return roslaunch.Node(self.package, self.type)
173
174
177 self.ctx = ctx
178 self.launch_file = launch_file
185
187 """
188 Node file filter function for list_resources. Filter functions
189 return the resource path if the filter matches, None otherwise.
190
191 @return: resource path (if match) or None
192 """
193 path = os.path.join(path, filename)
194 s = os.stat(path)
195 if (s.st_mode & stat.S_IRWXU == stat.S_IRWXU):
196 return path
197
199 """
200 roslaunch file filter function for list_resources. Filter
201 functions return the resource path if the filter matches, None
202 otherwise.
203
204 @return: resource path (if match) or None
205 """
206 if filename.endswith('.launch') or filename.endswith('.test'):
207 return os.path.join(path, filename)
208
209
213 resources = []
214 for p, dirs, files in os.walk(pkg_dir):
215 for f in files:
216 resource_path = filter_fn(p, f)
217 if resource_path is not None:
218 resources.append(resource_path)
219 if '.svn' in dirs:
220 dirs.remove('.svn')
221 elif '.git' in dirs:
222 dirs.remove('.git')
223 return resources
224
225 -class Stack(ManifestResource):
228
230 return roslib.stacks.get_stack_dir(self.name)
231
233 return roslib.stack_manifest.parse_file(os.path.join(path, roslib.stack_manifest.STACK_FILE))
234
238
239 packages = property(_get_packages)
240
242 - def __init__(self, ctx, lock, impl_class, list_fn):
243 super(ManifestResources, self).__init__(ctx, lock, impl_class)
244
245
246 self._list_cache = None
247 self._list_fn = list_fn
248 self._impl_class = impl_class
249
251 if self._list_cache is None:
252 self._list_cache = self._list_fn()
253 return self._list_cache
254
256 if key.startswith('_') or key == 'trait_names':
257 return object.__getattribute__(self, key)
258 else:
259 return self.__getitem__(key)
260
262 return (getattr(self, k) for k in self._getAttributeNames())
263
264 - def _get_entry(self, key):
265
266 if self._list_cache is None:
267 self._list_cache = self._list_fn()
268
269
270
271 if not key in self._list_cache:
272 raise AttributeError(key)
273 cache = self._config.cache
274 with self._config.lock:
275 if key in cache:
276 obj = cache[key]
277 else:
278
279
280 obj = self._impl_class(key, self._config)
281 cache[key] = obj
282 return obj
283
285 """
286 Dictionary-style accessor
287 """
288 if key in self._config.cache:
289 return self._config.cache[key]
290 else:
291 val = self._get_entry(key)
292 return val
293
298
299 -class Stacks(ManifestResources):
303