def GenerateDotGraph(package, deps_map, options): """Generates the dot source for the dependency graph leading to a node. The output is a list of lines. """ deps = GetReverseDependencyClosure(package, deps_map) node = deps_map[package] # Keep track of all the emitted nodes so that we don't issue multiple # definitions emitted = set() graph = dot_helper.Graph(package) # Add all the children if we want them, all of them in their own subgraph, # as a sink. Keep the arcs outside of the subgraph though (it generates # better layout). children_subgraph = None if options.children and node['deps']: children_subgraph = graph.AddNewSubgraph('sink') for child in node['deps']: child_node = deps_map[child] AddNodeToSubgraph(children_subgraph, child_node, options, CHILD_COLOR) emitted.add(child) graph.AddArc(package, child) # Add the package in its own subgraph. If we didn't have children, make it # a sink if children_subgraph: rank = 'same' else: rank = 'sink' package_subgraph = graph.AddNewSubgraph(rank) AddNodeToSubgraph(package_subgraph, node, options, TARGET_COLOR) emitted.add(package) # Add all the other nodes, as well as all the arcs. for dep in deps: dep_node = deps_map[dep] if not dep in emitted: color = NORMAL_COLOR if dep_node['action'] == 'seed': color = SEED_COLOR AddNodeToSubgraph(graph, dep_node, options, color) for j in dep_node['rev_deps']: graph.AddArc(j, dep) return graph.Gen()
def BuildDependencyGraph(pkg, input_deps, version_map, divergent_set): graph = dot_helper.Graph(pkg) # A subgraph for the divergent package we're considering. Add all its # versions as a sink. pkg_subgraph = graph.AddNewSubgraph('sink') # The outer packages are those that aren't divergent but depend on a # divergent package. Add them in their own subgraph, as sources. outer_subgraph = graph.AddNewSubgraph('source') emitted = set() for i in xrange(0, len(input_deps)): try: pkg_name = version_map[pkg][i] except KeyError: continue color = GetColor(i) if pkg_name not in emitted: pkg_subgraph.AddNode(pkg_name, pkg_name, color, None) emitted.add(pkg_name) # Add one subgraph per version for generally better layout. subgraph = graph.AddNewSubgraph() nodes = GetReverseDependencyClosure(pkg_name, input_deps[i], divergent_set) for node_name in nodes: if node_name not in emitted: subgraph.AddNode(node_name, node_name, color, None) emitted.add(node_name) # Add outer packages, and all the arcs. for dep in input_deps[i][node_name]['rev_deps']: dep_node = input_deps[i][dep] if (UnversionedName(dep_node) not in divergent_set and dep not in emitted): outer_subgraph.AddNode(dep, dep, NORMAL_COLOR, None) emitted.add(dep) graph.AddArc(dep, node_name) return graph