33 from __future__
import with_statement, print_function
38 from rospkg
import MANIFEST_FILE
39 from rospkg.common
import ResourceNotFound
44 for pattern
in patternlist:
47 if re.match(
"^[a-zA-Z0-9_]+$", pattern)
is None:
48 if re.match(pattern, name)
is not None:
57 :param rospack: use rospkg.RosPack() 58 :param rosstack: use rospkg.RosStack() 79 hide_transitives=
True,
92 :param hide_transitives: 93 if true, then dependency of children to grandchildren will be hidden if parent has 95 :param show_system: if true, then system dependencies will be shown 99 selected_names = filter(
lambda x: x
is not None and x !=
'', selected_names)
100 excludes = filter(
lambda x: x
is not None and x !=
'', excludes)
101 if selected_names
is None or selected_names == []:
102 selected_names = [
'.*']
110 "dotcode_factory": dotcode_factory,
111 "with_stacks": with_stacks,
113 "hide_transitives": hide_transitives,
114 "show_system": show_system,
115 "selected_names": selected_names,
116 "excludes": excludes,
117 "ancestors": ancestors,
118 "descendants": descendants,
119 "hide_wet": hide_wet,
124 selection_changed =
False 126 selection_changed =
True 141 if force_refresh
or selection_changed:
149 for name
in self.rospack.list():
155 for stackname
in self.rosstack.list():
157 manifest = self.rosstack.get_manifest(stackname)
158 if manifest.is_catkin:
164 for package_name
in self.rosstack.packages_of(stackname):
171 'dotcode_factory': dotcode_factory,
175 "simplify": simplify,
176 "colortheme": colortheme,
177 "mark_selected": mark_selected
181 display_changed =
False 183 display_changed =
True 196 if force_refresh
or selection_changed
or display_changed:
203 graph = dotcode_factory.get_graph(rank=self.
rank,
207 packages_in_stacks = []
209 for stackname
in self.
stacks:
218 color = get_color_for_string(stackname)
219 g = dotcode_factory.add_subgraph_to_graph(graph,
227 for package_name
in self.
stacks[stackname][
'packages']:
228 packages_in_stacks.append(package_name)
231 for package_name, attributes
in self.packages.items():
232 if package_name
not in packages_in_stacks:
234 for name1, name2
in self.edges.keys():
235 dotcode_factory.add_edge_to_graph(graph, name1, name2)
245 if attributes
and attributes[
'is_catkin']:
249 elif attributes
and not attributes[
'is_catkin']:
251 if attributes
and 'not_found' in attributes
and attributes[
'not_found']:
254 dotcode_factory.add_node_to_graph(graph, package_name, color=color)
257 if stackname
is None or stackname
in self.
stacks:
259 self.
stacks[stackname] = {
'packages': []}
263 adds object based on package_name to self.packages 264 :param parent: packagename which referenced package_name (for debugging only) 272 if catkin_package
is None:
274 self.
packages[package_name] = {
'is_catkin': catkin_package}
278 stackname = self.rospack.stack_of(package_name)
279 except ResourceNotFound
as e:
281 'RosPackageGraphDotcodeGenerator._add_package(%s), ' 282 'parent %s: ResourceNotFound:' % (package_name, parent), e)
284 if not stackname
is None and stackname !=
'':
285 if not stackname
in self.
stacks:
287 self.
stacks[stackname][
'packages'].append(package_name)
294 if self.
hide_wet and catkin_package:
296 if self.
hide_dry and catkin_package
is False:
304 package_path = self.rospack.get_path(package_name)
305 manifest_file = os.path.join(package_path, MANIFEST_FILE)
306 self.
package_types[package_name] =
not os.path.exists(manifest_file)
307 except ResourceNotFound:
314 self.
edges[(name1, name2)] = attributes
317 self, package_name, expanded_up=
None,
318 depth=
None, implicit=
False, parent=
None):
320 :param package_name: the name of package for which to add ancestors 321 :param expanded_up: names that have already been expanded (to avoid cycles) 322 :param depth: how many layers to follow 323 :param implicit: arg to rospack 324 :param parent: package that referenced package_name for error message only 328 if traversed_depth
is None:
330 if depth
is not None and traversed_depth >= depth:
341 if expanded_up
is None:
343 expanded_up.append(package_name)
346 depends_on = self.rospack.get_depends_on(package_name, implicit=implicit)
347 except ResourceNotFound
as e:
349 'RosPackageGraphDotcodeGenerator.add_package_ancestors_recursively(%s),' 350 ' parent %s: ResourceNotFound:' % (package_name, parent), e)
355 new_nodes.append(dep_on_name)
356 self.
_add_edge(dep_on_name, package_name)
358 expanded_up.append(dep_on_name)
359 for dep_on_name
in new_nodes:
361 expanded_up=expanded_up,
367 self, package_name, expanded=
None,
368 depth=
None, implicit=
False, parent=
None):
371 if traversed_depth
is None:
373 if depth
is not None and traversed_depth >= depth:
386 expanded.append(package_name)
390 depends = self.rospack.get_depends(package_name, implicit=implicit)
391 except ResourceNotFound:
393 manifest = self.rosstack.get_manifest(package_name)
394 if manifest.is_catkin:
395 depends = [d.name
for d
in manifest.depends]
398 except ResourceNotFound
as e:
400 'RosPackageGraphDotcodeGenerator.add_package_descendants_recursively(%s), ' 401 'parent: %s: ResourceNotFound:' % (package_name, parent), e)
405 rosdeps = self.rospack.get_rosdeps(package_name, implicit=implicit)
410 expanded.append(dep_name)
414 new_nodes.append(dep_name)
417 expanded.append(dep_name)
418 for dep_name
in new_nodes:
def _add_edge(self, name1, name2, attributes=None)
def __init__(self, rospack, rosstack)
def generate(self, dotcode_factory)
def _generate_package(self, dotcode_factory, graph, package_name, attributes=None)
def _hide_package(self, package_name)
def generate_dotcode(self, dotcode_factory, selected_names=[], excludes=[], depth=3, with_stacks=True, descendants=True, ancestors=True, hide_transitives=True, show_system=False, mark_selected=True, colortheme=None, rank='same', ranksep=0.2, rankdir='TB', simplify=True, force_refresh=False, hide_wet=False, hide_dry=False)
def _add_stack(self, stackname)
def add_package_ancestors_recursively(self, package_name, expanded_up=None, depth=None, implicit=False, parent=None)
def _add_package(self, package_name, parent=None)
def matches_any(name, patternlist)
def _is_package_wet(self, package_name)
def add_package_descendants_recursively(self, package_name, expanded=None, depth=None, implicit=False, parent=None)