コード例 #1
0
    def construct_superfluous_missing_multigraph(base_graph,
                                                 superfluous_deps_edges,
                                                 missing_deps_edges,
                                                 node_group_conf=None,
                                                 superfluous_color=Colors.RED,
                                                 missing_color=Colors.BLUE):
        superfluous_deps_graph = MutableAttributeGraph(
            edges=superfluous_deps_edges)
        missing_deps_graph = MutableAttributeGraph(edges=missing_deps_edges)

        if node_group_conf != None:
            base_graph = GraphCollapser.get_collapsed_graph(
                base_graph, node_group_conf)
            superfluous_deps_graph = GraphCollapser.get_collapsed_graph(
                superfluous_deps_graph, node_group_conf)
            missing_deps_graph = GraphCollapser.get_collapsed_graph(
                missing_deps_graph, node_group_conf)

        additional_graphs = [(superfluous_deps_graph, {
            EdgeAttributes.COLOR: superfluous_color,
            EdgeAttributes.WEIGHT: 5,
            EdgeAttributes.STYLE: EdgeStyles.DASHED
        }, True),
                             (missing_deps_graph, {
                                 EdgeAttributes.COLOR: missing_color,
                                 EdgeAttributes.WEIGHT: 5,
                                 EdgeAttributes.STYLE: EdgeStyles.DASHED
                             }, False)]
        multigraph = MultiGraphTools.construct_generic_multigraph(
            base_graph, additional_graphs)
        return multigraph
コード例 #2
0
 def test_filter_nothing_empty_graph_some_modules(self):
     full_graph = MutableAttributeGraph()
     filtered_graph = DefaultDependencyFilter.filter_graph(
         full_graph.immutable(),
         dependency_filter_config=NullDependencyFilterConfiguration(),
         internal_modules=["a"])
     self.assertEqual(["a"], sorted(filtered_graph.node_names()))
     self.assertEqual(0, filtered_graph.edge_count())
コード例 #3
0
 def graph_for_from_module(self, from_modules):
     if isinstance(from_modules, basestring):
         from_modules = (from_modules, )
     graph = MutableAttributeGraph()
     self.__graph = graph
     self.process_for_all_file_deps(lambda from_file, from_file_module, to_file, to_file_module: \
                                    graph.add_edge_and_nodes(from_file, to_file) if from_file_module in from_modules else None)
     self.__graph = None
     return graph
コード例 #4
0
 def __init__(self,
              config,
              module_list,
              default_edge_attrs=dict(),
              *args, **kwargs):
     assert isinstance(config, DependencyFilterConfiguration)
     self.__initial_config = config
     self.__full_graph = MutableAttributeGraph(default_edge_attrs=dict({EdgeAttributes.COLOR: "red"}))
     self.__logger = logging.getLogger(self.__class__.__module__)
     self.__module_list = module_list
     self.__graph = None
コード例 #5
0
 def __test(self):
     description = GraphDescriptionImpl(description="Test",
                                        basename="test",
                                        section="test")
     graph = MutableAttributeGraph()
     graph.add_edge_and_nodes("a", "b")
     module_group_conf = config_module_group_conf(
         module_grouper=config_module_grouper())
     DependencyFilterOutputterTools.output_detail_and_overview_graph(
         graph=graph,
         module_group_conf=module_group_conf,
         outputter=config_dependency_filter_outputter(),
         description=description)
コード例 #6
0
 def graph_for_modules(self, from_module, to_module):
     graph = MutableAttributeGraph()
     self.__graph = graph
     self.process_for_all_file_deps_matching_modules(
         graph.add_edge_and_nodes, from_module, to_module)
     self.__graph = None
     return graph
コード例 #7
0
 def _get(self):
     if self.__resultgraph == None:
         self.__resultgraph = MutableAttributeGraph(graph=self.__inputgraph)
         self.__original_nodes = set()
         self.__collapse_module_groups()
         self.__remove_original_nodes()
         self.__node_group_conf = None
         #self.__resultgraph.delete_unconnected_nodes()
     return self.__resultgraph
 def get_cluster_dependency_graph(self, clustering_result,
                                  base_dependency_graph):
     """
     @param clustering_result: 
     @param base_dependency_graph: A BasicGraph whose nodes are the elements of the clusters.
     @return: An AttributeGraph whose nodes are groups of nodes of the base_dependency_graph according to 
     the clusters.
     """
     cluster_graph = MutableAttributeGraph()
     clusters = clustering_result.values()
     for cluster in clusters:
         pseudomodule = self.__to_pseudomodule_list(cluster)
         cluster_graph.set_node_attrs(
             self.__make_nodename(pseudomodule), {
                 NodeAttributes.GROUPED_NODES: pseudomodule,
                 NodeAttributes.LABEL: ""
             }, True)
     for cluster_pair in product(clusters, clusters):
         if cluster_pair[0] != cluster_pair[1]:
             pseudomodule_pair = map(self.__to_pseudomodule_list,
                                     cluster_pair)
             if any(
                     base_dependency_graph.has_edge(edge[0], edge[1])
                     for edge in product(pseudomodule_pair[0],
                                         pseudomodule_pair[1])):
                 cluster_graph.add_edge_and_nodes(
                     self.__make_nodename(pseudomodule_pair[0]),
                     self.__make_nodename(pseudomodule_pair[1]))
     return cluster_graph
コード例 #9
0
 def run(self, output_filename):
     graph = MutableAttributeGraph(edges=(
         AttributedEdge(from_node="BTC.CAB.X.ClassA",
                        to_node="BTC.CAB.Y.B"),
         AttributedEdge(from_node="BTC.CAB.X.ClassC",
                        to_node="BTC.CAB.Y.B"),
         AttributedEdge(from_node="BTC.CAB.Z.ClassD",
                        to_node="BTC.CAB.Y.B"),
     ))
     graph.lookup_edge("BTC.CAB.X.ClassA", "BTC.CAB.Y.B").set_attrs(
         {EdgeAttributes.COLOR: Colors.RED})
     outfile = open(output_filename, "w")
     outputter = self.__graph_outputter_class(
         graph=graph,
         outfile=outfile,
         decorator_config=DecoratorSet(
             node_label_decorators=(MyNodeColorDecorator(), ), ),
         output_groups=True,
         node_grouper=CABStyleFinestLevelModuleGrouperInternal(
             modules=graph.node_names(),
             internal_modules=graph.node_names(),
             min_parts=3),
         description=GraphDescriptionImpl(description="test",
                                          basename=output_filename))
     outputter.output_all()
コード例 #10
0
 def construct_graph(source, target, color):
     attr_graph = MutableAttributeGraph(
         default_edge_attrs=dict({EdgeAttributes.COLOR: color}))
     attr_graph.add_node(source)
     attr_graph.add_node(target)
     attr_graph.add_edge(source, target)
     return attr_graph
コード例 #11
0
 def test_filter_nothing_nonempty_graph_additional_module(self):
     full_graph = MutableAttributeGraph()
     full_graph.add_edge_and_nodes("a", "b")
     full_graph.add_edge_and_nodes("b", "c")
     full_graph.add_edge_and_nodes("d", "a")
     filtered_graph = DefaultDependencyFilter.filter_graph(
         full_graph.immutable(),
         dependency_filter_config=NullDependencyFilterConfiguration(),
         internal_modules=["a", "e"])
     self.assertEqual(["a", "b", "c", "d", "e"],
                      sorted(filtered_graph.node_names()))
     self.assertEqual(3, filtered_graph.edge_count())
コード例 #12
0
ファイル: output_base.py プロジェクト: sigiesec/revengtools
 def __init__(self, output_groups, graph, outfile,
              node_grouper,
              decorator_config,
              generation_log, 
              description = None,
              *args, **kwargs):
     GraphOutputter.__init__(self, output_groups, graph, outfile, node_grouper, *args, **kwargs) 
     assert isinstance(graph, BasicGraph)
     if node_grouper != None:
         assert isinstance(node_grouper, NodeGrouper)
     else:
         node_grouper = NullNodeGrouper() 
     
     self.__logger = logging.getLogger(self.__class__.__module__)
     self.__do_output_groups = output_groups
     self.__graph = MutableAttributeGraph(graph=graph)
     self.__outfile = outfile
     self.__node_grouper = node_grouper
     self.__decorator_config = decorator_config
     self.__description = description
     self.__generation_log = generation_log
コード例 #13
0
    def filter_graph(full_graph, dependency_filter_config, internal_modules):
        """
        
        @param full_graph:
        @param dependency_filter_config:
        @param internal_modules: All internal modules are added to the graph even if they are not 
            connected to any other module. If the graph is focused on a particular module group, 
            this applies only if they belong to this module group.
        """
        graph = MutableAttributeGraph()
        for module in internal_modules:
            if not dependency_filter_config.skip_module(module) and not dependency_filter_config.skip_module_as_source(module):
                graph.add_node(module)
        for edge in full_graph.edges():
            source = str(edge.get_from_node())
            target = str(edge.get_to_node())
            if not (dependency_filter_config.skip_module(source) \
                    or dependency_filter_config.skip_module(target) \
                    or dependency_filter_config.skip_module_as_source(source) \
                    or dependency_filter_config.skip_module_as_target(target) \
                    or dependency_filter_config.skip_edge(source, target)):
                graph.add_edge_and_nodes(source, target)
            else:
                if dependency_filter_config.skip_module_as_source(source) or dependency_filter_config.skip_edge(source, target):
                    #self.__logger.debug("recording skipped edge source %s->%s", source, target)
                    graph.set_node_attrs(source, {NodeAttributes.SKIPPED_FROM_EDGE: True}, True)
                if dependency_filter_config.skip_module_as_target(target) or dependency_filter_config.skip_edge(source, target):
                    #self.__logger.debug("recording skipped edge target %s->%s", source, target)
                    graph.set_node_attrs(target, {NodeAttributes.SKIPPED_TO_EDGE: True}, True)

        if dependency_filter_config.focus_on_node_groups:
            node_grouper = dependency_filter_config.get_module_grouper()
            exception_func = lambda node: node_grouper.get_node_group_prefix(node) in dependency_filter_config.focus_on_node_groups
        else:
            exception_func = lambda node: False
        graph.delete_unconnected_nodes(exception_func)
        return graph
コード例 #14
0
class DefaultDependencyFilter(DependencyFilter):
    """
    This class is not intended to be subclassed.
    """
    
    _supports_grouping = True

    def __init__(self,
                 config,
                 module_list,
                 default_edge_attrs=dict(),
                 *args, **kwargs):
        assert isinstance(config, DependencyFilterConfiguration)
        self.__initial_config = config
        self.__full_graph = MutableAttributeGraph(default_edge_attrs=dict({EdgeAttributes.COLOR: "red"}))
        self.__logger = logging.getLogger(self.__class__.__module__)
        self.__module_list = module_list
        self.__graph = None

    def __get_module_list(self):
        return self.__module_list

    def _edges(self):
        warnings.warn("use _graph().edges()", DeprecationWarning)
        return self.__graph.edges()

#    def _config(self):
#        return self.__initial_config

#    def _graph(self):
#        return self.__graph

#    def set_node_size(self, node, height, width):
#        self.__graph.set_node_attrs(node, {NodeAttributes.HEIGHT: height,
#                                            NodeAttributes.WIDTH: width}, create=True)

#    def set_node_shape(self, node, shape):
#        self.__graph.set_node_attrs(node, {NodeAttributes.SHAPE: shape}, create=True)

    def dependency(self, source, target):
        self.__full_graph.add_edge_and_nodes(source, target)

    @staticmethod
    def filter_graph(full_graph, dependency_filter_config, internal_modules):
        """
        
        @param full_graph:
        @param dependency_filter_config:
        @param internal_modules: All internal modules are added to the graph even if they are not 
            connected to any other module. If the graph is focused on a particular module group, 
            this applies only if they belong to this module group.
        """
        graph = MutableAttributeGraph()
        for module in internal_modules:
            if not dependency_filter_config.skip_module(module) and not dependency_filter_config.skip_module_as_source(module):
                graph.add_node(module)
        for edge in full_graph.edges():
            source = str(edge.get_from_node())
            target = str(edge.get_to_node())
            if not (dependency_filter_config.skip_module(source) \
                    or dependency_filter_config.skip_module(target) \
                    or dependency_filter_config.skip_module_as_source(source) \
                    or dependency_filter_config.skip_module_as_target(target) \
                    or dependency_filter_config.skip_edge(source, target)):
                graph.add_edge_and_nodes(source, target)
            else:
                if dependency_filter_config.skip_module_as_source(source) or dependency_filter_config.skip_edge(source, target):
                    #self.__logger.debug("recording skipped edge source %s->%s", source, target)
                    graph.set_node_attrs(source, {NodeAttributes.SKIPPED_FROM_EDGE: True}, True)
                if dependency_filter_config.skip_module_as_target(target) or dependency_filter_config.skip_edge(source, target):
                    #self.__logger.debug("recording skipped edge target %s->%s", source, target)
                    graph.set_node_attrs(target, {NodeAttributes.SKIPPED_TO_EDGE: True}, True)

        if dependency_filter_config.focus_on_node_groups:
            node_grouper = dependency_filter_config.get_module_grouper()
            exception_func = lambda node: node_grouper.get_node_group_prefix(node) in dependency_filter_config.focus_on_node_groups
        else:
            exception_func = lambda node: False
        graph.delete_unconnected_nodes(exception_func)
        return graph

    def __color_nodes(self):
        warnings.warn("use a node decorator instead", DeprecationWarning)
        for node in self.__full_graph.node_names_iter():
            color = self.__initial_config.get_node_color(str(node))
            self.__graph.set_node_attrs(node, {NodeAttributes.FILL_COLOR: color})

    def __color_edges(self):
        # TODO besser in einem Decorator. Wird das überhaupt noch benutzt?
        for edge in self.__full_graph.edges():
            edge.set_attrs({EdgeAttributes.COLOR:
                            self.__initial_config.get_edge_color(str(edge.get_from_node()),
                                                         str(edge.get_to_node())
                                                         )})

    def postamble(self):
        #self.__color_nodes()
        self.__color_edges()
        graph = self.filter_graph(full_graph=self.__full_graph, 
                                  dependency_filter_config=self.__initial_config,
                                  internal_modules=self.__get_module_list())
        self.__graph = graph.immutable()

    def graph(self):
        #return self.__graph.immutable()
        return MutableAttributeGraph(graph=self.__graph)
コード例 #15
0
 def graph(self):
     #return self.__graph.immutable()
     return MutableAttributeGraph(graph=self.__graph)
コード例 #16
0
 def test_empty(self):
     graph = MutableAttributeGraph()
     self._run_with_graph(graph)
コード例 #17
0
    def aggregate_graph(mapper, ignore_external, exceptions, file_graph):
        assert (isinstance(mapper, AggregateMapper))
        pseudomodule_graph = MutableAttributeGraph()
        for edge in file_graph.edges():
            from_node = mapper.get_output_aggregate_for_individual(
                edge.get_from_node())
            if mapper.is_file_in_input_aggregates(edge.get_to_node()):
                to_node = mapper.get_output_aggregate_for_individual(
                    edge.get_to_node())
                if not (from_node == to_node or
                        (from_node, to_node) in exceptions):
                    pseudomodule_graph.add_edge_and_nodes(from_node, to_node)
                else:
                    pseudomodule_graph.add_node(from_node)
                    pseudomodule_graph.add_node(to_node)
            elif not ignore_external:
                to_node = edge.get_to_node()
                pseudomodule_graph.add_edge_and_nodes(from_node, to_node)
            else:
                pseudomodule_graph.add_node(from_node)

        # TODO warum wird das gemacht?
        for node in pseudomodule_graph.nodes_raw():
            pseudomodule_graph.set_node_attrs(node, {NodeAttributes.LABEL: ""})

        return pseudomodule_graph