Beispiel #1
0
def main():
    logging.basicConfig(stream=sys.stderr,level=logging.DEBUG)
    Configurator().default()
    
    file_links = config_file_include_deps_supply.get_file_include_deps()
    
    report_filename = os.path.join(config_basic.get_results_directory(),
                                   "IncludeDeps",
                                   "include_rule_report.txt")
    
    illegal_links, total_count, rule_violations = IncludeRuleCheckerProcessor().check_links(file_links, config_checker.get_include_rules())
    IncludeRuleCheckerOutputter().output(open(report_filename, "w"), illegal_links, total_count, rule_violations)

    description = GraphDescriptionImpl(description="file-level include deps",
                                       category="report")
    config_generation_log.add_generated_file(description=description,
                                             filename=report_filename)
def main():
    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
    Configurator().default()

    module_name = 'BtcCommonsCore'
    restrict_to_headers = False

    file_to_module_map = config_file_to_module_map_supply.generate_file_to_module_map(
        False)
    all_file_links = config_file_include_deps_supply.get_file_include_deps()
    module_file_links = (AttributedEdge(from_node=from_file, to_node=to_file)
                         for (from_file, to_file) in all_file_links
                         if from_file in file_to_module_map and \
                         VirtualModuleTypes.remove_suffixes(file_to_module_map[from_file]) == module_name and \
                         (not restrict_to_headers or from_file.endswith('.h')))
    #pprint(list(module_file_links))
    # TODO is this correct? does the output graph contain anything if the module list is empty?
    dependency_filter = DefaultDependencyFilter(
        config=MyDependencyFilterConfiguration(), module_list=())
    #module_list=set(edge.get_from_node() for edge in module_file_links))
    graph = DependencyFilterHelper.filter_graph(
        dependency_filter=dependency_filter,
        graph=AttributeGraph(edges=module_file_links))

    decorator_config = DecoratorSet(
        edge_label_decorators=[SCCEdgeDecorator()],
        node_label_decorators=[
            NodeSizeLabelDecorator(size_func=FileSizer.get_file_size),
            NodeSizeScalingDecorator(size_func=FileSizer.get_file_size,
                                     min_render_size=3,
                                     max_render_size=14,
                                     scale_type=ScalingTypes.RADICAL),
            ModuleColorNodeDecorator(EPMNodeColorer()),
        ])
    graph_description = GraphDescriptionImpl(
        description="internal include dependencies of %s" % module_name,
        basename=os.path.join(config_basic.get_results_directory(),
                              module_name),
        section='module-internal')
    DependencyFilterOutputterTools.output_detail_and_overview_graph(
        graph=graph,
        #decorator_config=decorator_config,
        description=graph_description,
        outputter=DependencyFilterOutputter(decorator_config=decorator_config),
        module_group_conf=MyNodeGroupingConfiguration(MyNodeGrouper()))
    def output_combined_graph(self, show_combined_graph, multigraph,
                              overview_multigraph):
        output_basename = FileModuleIncludeDepsSupply().get_module_include_deps_basename() \
            + "-consistency"
        decorator_config = DecoratorSet(edge_tooltip_decorators=[
            ModuleIncludeLinkDetailsDecorator(self.__file_include_deps_printer)
        ])

        description = GraphDescriptionImpl(
            description=ConsistencyCheckerOutputConstants.DESCRIPTION_STRING,
            basename=output_basename,
            legend="red=missing, blue=irregular link deps")
        DependencyFilterOutputterTools.output_detail_and_overview_graph \
                (graph=multigraph,
                 overview_graph=overview_multigraph,
                 module_group_conf=self.__node_group_conf(self.__module_grouper),
                 outputter=self.__dependency_filter_outputter(decorator_config),
                 description=description)
Beispiel #4
0
    def process(self, show=False):
        self._parser = config_dependency_parser()
        self._parser.process()
        dep_filter = config_dependency_filter(
            config=config_dependency_filter_config)
        self._parser.output(dep_filter)

        decorator_conf = DecoratorSet(
            node_tooltip_decorators=[NodeGroupDecorator()],
            edge_tooltip_decorators=[EdgeGroupDecorator()])
        basename = self.__generic_files_tools.get_module_link_deps_basename(
        ) + '-sub-custom'
        outputter = config_dependency_filter_outputter(decorator_conf)

        graph = dep_filter.graph()
        # TODO Momentan nur ein Test!
        #start_nodes = ['osapi', 'prio4dyn', 'dyn', 'prid4dynmfc', 'bib']
        if config_basic.get_system() == 'prins':
            start_nodes = set(ifilter(is_prins_classic,
                                      graph.node_names())) - set(['osapi'])
            description = GraphDescriptionImpl(
                description=
                "subgraph: modules independent of legacy PRINS (link deps)")
        elif config_basic.get_system() == 'revengtools':
            start_nodes = set(
                ifilter(
                    lambda x: x.startswith(('infrastructure', 'cpp', 'python',
                                            'systems', 'commons.graph')),
                    graph.node_names()))
            description = GraphDescriptionImpl(
                description="subgraph: generic core")
        else:
            raise RuntimeError("Unknown system %s" % config_basic.get_system())
        GraphAlgorithms.remove_subgraph_dependent_on_nodes(graph, start_nodes)

        description.set_basename(basename)
        description.set_section('subgraph')

        DependencyFilterOutputterTools.output_detail_and_overview_graph(
            graph, outputter, description=description)
Beispiel #5
0
    def output_graph(
        self,
        output_filename=None,  # @deprecated: use description instead
        outfile=None,
        graph_outputter_factory=None,
        graph=None,
        node_group_conf=None,
        collapse=True,
        description=None,
        generation_log=None,
        add_graph_outputter_options=dict()):
        if not generation_log:
            warnings.warn("a generation log should be passed to output_graph")
            generation_log = config_generation_log
        if description != None:
            if isinstance(description, basestring):
                warnings.warn(
                    "passing string as description is deprecated, pass GraphDescription object instead",
                    DeprecationWarning)
                description = GraphDescriptionImpl(description=description,
                                                   basename=output_filename)
            else:
                if output_filename != None:
                    raise ValueError(
                        "do not set output_filename if description==GraphDescriptionImpl(...)"
                    )
        if outfile == None:
            output_filename = description.get_filename()
            if output_filename != None:
                # TODO replace graph_outputter_class by a proper abstract factory
                outfile = open(
                    output_filename +
                    graph_outputter_factory.usual_extension(), "w")
            else:
                pass
                #raise ValueError("Must specify either outfile or output_filename")
                # TODO this depends on the graph_outputter_class... this is true only if it outputs to a file

        # Assume a MultiGraph is already collapsed
        if collapse and not isinstance(graph, MultiGraph):
            assert node_group_conf != None and isinstance(
                node_group_conf, NodeGroupingConfiguration)
            graph = GraphCollapser.get_collapsed_graph(graph, node_group_conf)

        node_grouper = None
        if node_group_conf != None:
            node_grouper = node_group_conf.get_node_grouper()

        self.__logger.info(
            "Writing graph %s to %s using outputter %s and grouping config %s"
            % (graph, outfile, graph_outputter_factory.get_name(),
               node_group_conf))

        graph_outputter = \
            graph_outputter_factory.create_instance(output_groups=True,
                                  graph=graph,
                                  outfile=outfile,
                                  node_grouper=node_grouper,
                                  decorator_config=self.get_decorator_config(output_filename),
                                  description=description,
                                  generation_log=generation_log,
                                  **add_graph_outputter_options)
        graph_outputter.output_all()
        # TODO die ganze Fallunterscheidung sollte hier entfernt werden.
        #        if isinstance(graph_outputter, GraphicalGraphOutputter) and output_filename != None:
        #            outfile.close()
        #            graph_outputter.render_file(filename=output_filename, description=description)
        #        else:
        graph_outputter.register_log()
        return graph_outputter
 def __get_description(self):
     dot_filename = self.__generic_files_tools.get_module_link_deps_basename() + "-epm-rules"
     description = GraphDescriptionImpl(basename=dot_filename,
         description="EPM physical rule violations based on module-level link dependencies")
     return description
Beispiel #7
0
def main():
    logging.basicConfig(stream=sys.stderr, level=logging.INFO)
    #logging.getLogger("commons.configurator").setLevel(logging.DEBUG)
    Configurator().default()

    usage = "usage: %prog [options]"
    parser = OptionParser(usage)
    #    parser.add_option("-s", "--show", dest="show",
    #                      help="open the resulting graph output after generation")
    parser.add_option("",
                      "--no_graphs",
                      action="store_false",
                      dest="generate_graphs",
                      help="disable graph generation completely")
    parser.add_option("-g",
                      "--focus_on_each_group",
                      action="store_true",
                      dest="focus_on_each_group",
                      help="output separate graphs for each module group")
    parser.add_option("-l",
                      "--list_modules",
                      action="store_true",
                      dest="list_modules",
                      help="generate a module list")
    parser.set_defaults(show=False,
                        focus_on_each_group=False,
                        list_modules=False,
                        generate_graphs=True)
    (options, _args) = parser.parse_args()

    Configurator().create_instance(ParseLinkDependencies).process(
        show=options.show,
        focus_on_each_group=options.focus_on_each_group,
        generate_graphs=options.generate_graphs)

    if options.list_modules:
        generation_logger = config_generation_log

        #TODO: Kann das schoener über eine for Schleife geloest werden?
        report_filename = os.path.join(config_basic.get_results_directory(),
                                       "module_list.html")
        if (HTMLModuleLister(output_file=open(report_filename, "w"),
                             analysis_info=(config_basic.get_system(),
                                            config_basic.get_version(),
                                            "Unknown"),
                             module_list_supply=config_module_list).write()):
            description = GraphDescriptionImpl(description="module list",
                                               category="report")
            generation_logger.add_generated_file(description=description,
                                                 filename=report_filename)

        report_filename = os.path.join(config_basic.get_results_directory(),
                                       "results_per_rule_list.html")
        if (HTMLRuleLister(
                output_file=open(report_filename, "w"),
                analysis_info=(
                    config_basic.get_system(),
                    config_basic.get_version(),
                    "Unknown",
                ),
                module_list_supply=config_module_list,
                output_type=HTMLRuleListerOutputType.RESULTS_PER_RULE).write()
            ):
            description = GraphDescriptionImpl(description="results per rule",
                                               category="report")
            generation_logger.add_generated_file(description=description,
                                                 filename=report_filename)

        report_filename = os.path.join(config_basic.get_results_directory(),
                                       "results_per_subject_list.html")
        if (HTMLRuleLister(output_file=open(report_filename, "w"),
                           analysis_info=(config_basic.get_system(),
                                          config_basic.get_version(),
                                          "Unknown"),
                           module_list_supply=config_module_list,
                           output_type=HTMLRuleListerOutputType.
                           RESULTS_PER_SUBJECT).write()):
            description = GraphDescriptionImpl(
                description="results per subject", category="report")
            generation_logger.add_generated_file(description=description,
                                                 filename=report_filename)

        report_filename = os.path.join(config_basic.get_results_directory(),
                                       "rule_overview.html")
        if (HTMLRuleLister(
                output_file=open(report_filename, "w"),
                analysis_info=(config_basic.get_system(),
                               config_basic.get_version(), "Unknown"),
                module_list_supply=config_module_list,
                output_type=HTMLRuleListerOutputType.RULE_OVERVIEW).write()):
            description = GraphDescriptionImpl(description="rules",
                                               category="overview")
            generation_logger.add_generated_file(description=description,
                                                 filename=report_filename)

        report_filename = os.path.join(config_basic.get_results_directory(),
                                       "checkstyle_result.xml")
        if (XMLRuleLister(
                output_file=open(report_filename, "w"),
                module_list_supply=config_module_list,
                output_type=XMLRuleListerOutputType.CHECKSTYLE_XML).write()):
            description = GraphDescriptionImpl(
                description="results per subject", category="report")
            generation_logger.add_generated_file(description=description,
                                                 filename=report_filename)
        report_filename = os.path.join(config_basic.get_results_directory(),
                                       "revengtools_result.xml")
        if (XMLRuleLister(
                output_file=open(report_filename, "w"),
                module_list_supply=config_module_list,
                output_type=XMLRuleListerOutputType.REVENGTOOLS_XML).write()):
            description = GraphDescriptionImpl(
                description="results per subject", category="report")
            generation_logger.add_generated_file(description=description,
                                                 filename=report_filename)
        report_filename = os.path.join(config_basic.get_results_directory(),
                                       "revengtools.xsd")
        description = GraphDescriptionImpl(description="results per subject",
                                           category="overview")
        generation_logger.add_generated_file(description=description,
                                             filename=report_filename)
def main():
    logging.basicConfig(stream=sys.stderr, level=logging.WARNING)
    Configurator().default()

    if len(sys.argv) < 1:
        print(
            "usage: %s <comma-separated list of module names> <comma-separated list of options>"
            % (sys.argv[0]))
        print("valid options:")
        print(
            "  graph: Output a graph (otherwise, only dependency metrics are calculated)"
        )
        print("  external: Include include dependency across module bounds")
        print("  merge: Merge cycles into one node")
        sys.exit(1)

    output_graph = False
    ignore_external = True
    merge_sccs = False

    exceptions = set()
    modulenames = set(sys.argv[1].split(","))
    # TODO !!!
    if "BtcCommonsCore" in modulenames:
        exceptions = set((("stringnumconvint", "hashmap"), ))
        pass

    if len(sys.argv) > 2:
        options = set(sys.argv[2].split(","))
        if 'graph' in options:
            output_graph = True
        if 'external' in options:
            ignore_external = False
        if 'merge' in options:
            merge_sccs = True

    file_to_module_map = config_file_to_module_map_supply.generate_file_to_module_map(
    )
    file_name_mapper = FileNameMapper(file_to_module_map, modulenames)
    generator = FileLevelPseudoModuleDependencyGenerator(
        file_to_module_map=file_to_module_map)
    merged_graph = generator.get_file_level_pseudomodule_graph(
        modulenames=modulenames,
        mapper=file_name_mapper,
        ignore_external=ignore_external,
        exceptions=exceptions)

    logging.debug(merged_graph)
    cdm = ComponentDependencyMetric(merged_graph)
    print("Internal file-level CCD of %s is %i, nCCD=%f, ACD=%f" %
          (", ".join(modulenames), cdm.calculate_ccd(), cdm.calculate_nccd(),
           cdm.calculate_acd()))

    if merge_sccs:
        merger = SCCMerger(merged_graph)
        merged_graph = merger.get_scc_merged_graph()
        if merger.get_sccs_iter():
            print("SCCs:")
            for (i, scc) in enumerate(merger.get_sccs_iter()):
                print("  SCC %i: %s" % (i, ", ".join(scc)))
                print()

    if output_graph:
        node_grouper = config_node_grouper_class()
        node_grouper.configure_nodes(merged_graph.node_names_iter())
        basename = os.path.join(
            config_basic.get_results_directory(),
            'include_links_for_module-%s' % ("-".join(modulenames), ))
        size_fun = PseudoModuleSizer(
            file_name_mapper,
            path_resolver=FixedBaseDirPathResolver(
                config_basic.get_local_source_base_dir())).module_size
        decorator_config = DecoratorSet(
            node_label_decorators=(
                NodeSizeLabelDecorator(size_func=size_fun),
                NodeGroupDecorator(),
                NodeSizeScalingDecorator(min_render_size=1.5,
                                         max_render_size=8,
                                         size_func=size_fun),
            ),
            edge_label_decorators=(SCCEdgeDecorator(), ),
            node_tooltip_decorators=(),
            edge_tooltip_decorators=())

        description = GraphDescriptionImpl(
            description="file-level pseudomodule include dependencies",
            basename=basename,
            extra="(%s->*)" % (", ".join(modulenames), ))
        DependencyFilterOutputter(decorator_config).output(
            filter=None,
            graph=merged_graph,
            module_group_conf=DefaultNodeGroupingConfiguration(
                node_grouper=node_grouper),
            description=description)