parameters: (self, deps, out)
docstring: Computes nodes' and edges' properties for the dependency graph |deps| and
      carries out the actual dumping to a file/pipe |out|.
docstring_summary: Computes nodes' and edges' properties for the dependency graph |deps| and
      carries out the actual dumping to a file/pipe |out|.
docstring_tokens: Computes nodes and edges properties for the dependency graph |deps| and carries out the actual dumping to a file / pipe |out| .
function: def _DumpDependenciesImpl(self, deps, out):
      """Computes nodes' and edges' properties for the dependency graph |deps| and
      carries out the actual dumping to a file/pipe |out|."""
      deps_graph = dict()
      deps_srcs = set()
  
      # Pre-initialize the graph with src->(dst, allow) pairs.
      for (allow, src, dst) in deps:
        if allow == Rule.TEMP_ALLOW and self.ignore_temp_rules:
          continue
  
        deps_srcs.add(src)
        if src not in deps_graph:
          deps_graph[src] = []
        deps_graph[src].append((dst, allow))
  
        # Add all hierarchical parents too, in case some of them don't have their
        # own DEPS, and therefore are missing from the list of rules. Those will
        # be recursively populated with their parents' rules in the next block.
        parent_src = os.path.dirname(src)
        while parent_src:
          if parent_src not in deps_graph:
            deps_graph[parent_src] = []
          parent_src = os.path.dirname(parent_src)
  
      # For every node, propagate its rules down to all its children.
      deps_srcs = list(deps_srcs)
      deps_srcs.sort()
      for src in deps_srcs:
        parent_src = os.path.dirname(src)
        if parent_src:
          # We presort the list, so parents are guaranteed to precede children.
          assert parent_src in deps_graph,\
                 "src: %s, parent_src: %s" % (src, parent_src)
          for (dst, allow) in deps_graph[parent_src]:
            # Check that this node does not explicitly override a rule from the
            # parent that we're about to add.
            if ((dst, Rule.ALLOW) not in deps_graph[src]) and \
               ((dst, Rule.TEMP_ALLOW) not in deps_graph[src]) and \
               ((dst, Rule.DISALLOW) not in deps_graph[src]):
              deps_graph[src].append((dst, allow))
  
      node_props = {}
      edges = []
  
      # 1) Populate a list of edge specifications in DOT format;
      # 2) Populate a list of computed raw node attributes to be output as node
      #    specifications in DOT format later on.
      # Edges and nodes are emphasized with color and line/border weight depending
      # on how many of incl/excl/hilite_fanins/hilite_fanouts filters they hit,
      # and in what way.
      for src in deps_graph.keys():
        for (dst, allow) in deps_graph[src]:
          if allow == Rule.DISALLOW and self.hide_disallowed_deps:
            continue
  
          if allow == Rule.ALLOW and src == dst:
            continue
  
          edge_spec = "%s->%s" % (src, dst)
          if not re.search(self.incl, edge_spec) or \
                 re.search(self.excl, edge_spec):
            continue
  
          if src not in node_props:
            node_props[src] = {'hilite': None, 'degree': 0}
          if dst not in node_props:
            node_props[dst] = {'hilite': None, 'degree': 0}
  
          edge_weight = 1
  
          if self.hilite_fanouts and re.search(self.hilite_fanouts, src):
            node_props[src]['hilite'] = 'lightgreen'
            node_props[dst]['hilite'] = 'lightblue'
            node_props[dst]['degree'] += 1
            edge_weight += 1
  
          if self.hilite_fanins and re.search(self.hilite_fanins, dst):
            node_props[src]['hilite'] = 'lightblue'
            node_props[dst]['hilite'] = 'lightgreen'
            node_props[src]['degree'] += 1
            edge_weight += 1
  
          if allow == Rule.ALLOW:
            edge_color = (edge_weight > 1) and 'blue' or 'green'
            edge_style = 'solid'
          elif allow == Rule.TEMP_ALLOW:
            edge_color = (edge_weight > 1) and 'blue' or 'green'
            edge_style = 'dashed'
          else:
            edge_color = 'red'
            edge_style = 'dashed'
          edges.append('    "%s" -> "%s" [style=%s,color=%s,penwidth=%d];' % \
              (src, dst, edge_style, edge_color, edge_weight))
  
      # Reformat the computed raw node attributes into a final DOT representation.
      nodes = []
      for (node, attrs) in node_props.iteritems():
        attr_strs = []
        if attrs['hilite']:
          attr_strs.append('style=filled,fillcolor=%s' % attrs['hilite'])
        attr_strs.append('penwidth=%d' % (attrs['degree'] or 1))
        nodes.append('    "%s" [%s];' % (node, ','.join(attr_strs)))
  
      # Output nodes and edges to |out| (can be a file or a pipe).
      edges.sort()
      nodes.sort()
      out.write('digraph DEPS {\n'
                '    fontsize=8;\n')
      out.write('\n'.join(nodes))
      out.write('\n\n')
      out.write('\n'.join(edges))
      out.write('\n}\n')
      out.close()
function_tokens: def _DumpDependenciesImpl ( self , deps , out ) : deps_graph = dict ( ) deps_srcs = set ( ) # Pre-initialize the graph with src->(dst, allow) pairs. for ( allow , src , dst ) in deps : if allow == Rule . TEMP_ALLOW and self . ignore_temp_rules : continue deps_srcs . add ( src ) if src not in deps_graph : deps_graph [ src ] = [ ] deps_graph [ src ] . append ( ( dst , allow ) ) # Add all hierarchical parents too, in case some of them don't have their # own DEPS, and therefore are missing from the list of rules. Those will # be recursively populated with their parents' rules in the next block. parent_src = os . path . dirname ( src ) while parent_src : if parent_src not in deps_graph : deps_graph [ parent_src ] = [ ] parent_src = os . path . dirname ( parent_src ) # For every node, propagate its rules down to all its children. deps_srcs = list ( deps_srcs ) deps_srcs . sort ( ) for src in deps_srcs : parent_src = os . path . dirname ( src ) if parent_src : # We presort the list, so parents are guaranteed to precede children. assert parent_src in deps_graph , "src: %s, parent_src: %s" % ( src , parent_src ) for ( dst , allow ) in deps_graph [ parent_src ] : # Check that this node does not explicitly override a rule from the # parent that we're about to add. if ( ( dst , Rule . ALLOW ) not in deps_graph [ src ] ) and ( ( dst , Rule . TEMP_ALLOW ) not in deps_graph [ src ] ) and ( ( dst , Rule . DISALLOW ) not in deps_graph [ src ] ) : deps_graph [ src ] . append ( ( dst , allow ) ) node_props = { } edges = [ ] # 1) Populate a list of edge specifications in DOT format; # 2) Populate a list of computed raw node attributes to be output as node #    specifications in DOT format later on. # Edges and nodes are emphasized with color and line/border weight depending # on how many of incl/excl/hilite_fanins/hilite_fanouts filters they hit, # and in what way. for src in deps_graph . keys ( ) : for ( dst , allow ) in deps_graph [ src ] : if allow == Rule . DISALLOW and self . hide_disallowed_deps : continue if allow == Rule . ALLOW and src == dst : continue edge_spec = "%s->%s" % ( src , dst ) if not re . search ( self . incl , edge_spec ) or re . search ( self . excl , edge_spec ) : continue if src not in node_props : node_props [ src ] = { 'hilite' : None , 'degree' : 0 } if dst not in node_props : node_props [ dst ] = { 'hilite' : None , 'degree' : 0 } edge_weight = 1 if self . hilite_fanouts and re . search ( self . hilite_fanouts , src ) : node_props [ src ] [ 'hilite' ] = 'lightgreen' node_props [ dst ] [ 'hilite' ] = 'lightblue' node_props [ dst ] [ 'degree' ] += 1 edge_weight += 1 if self . hilite_fanins and re . search ( self . hilite_fanins , dst ) : node_props [ src ] [ 'hilite' ] = 'lightblue' node_props [ dst ] [ 'hilite' ] = 'lightgreen' node_props [ src ] [ 'degree' ] += 1 edge_weight += 1 if allow == Rule . ALLOW : edge_color = ( edge_weight > 1 ) and 'blue' or 'green' edge_style = 'solid' elif allow == Rule . TEMP_ALLOW : edge_color = ( edge_weight > 1 ) and 'blue' or 'green' edge_style = 'dashed' else : edge_color = 'red' edge_style = 'dashed' edges . append ( '    "%s" -> "%s" [style=%s,color=%s,penwidth=%d];' % ( src , dst , edge_style , edge_color , edge_weight ) ) # Reformat the computed raw node attributes into a final DOT representation. nodes = [ ] for ( node , attrs ) in node_props . iteritems ( ) : attr_strs = [ ] if attrs [ 'hilite' ] : attr_strs . append ( 'style=filled,fillcolor=%s' % attrs [ 'hilite' ] ) attr_strs . append ( 'penwidth=%d' % ( attrs [ 'degree' ] or 1 ) ) nodes . append ( '    "%s" [%s];' % ( node , ',' . join ( attr_strs ) ) ) # Output nodes and edges to |out| (can be a file or a pipe). edges . sort ( ) nodes . sort ( ) out . write ( 'digraph DEPS {\n' '    fontsize=8;\n' ) out . write ( '\n' . join ( nodes ) ) out . write ( '\n\n' ) out . write ( '\n' . join ( edges ) ) out . write ( '\n}\n' ) out . close ( )