Exemplo n.º 1
0
 def __get_module_to_txt_map(self):
     # TODO das gibt letztlich eine item iterator zurück
     if self.__module_to_txt_map == None:
         self.__module_to_txt_map = SetValuedDictTools.convert_from_itemiterator(
             NormalizedPathsIter.create(
                 filename=self.get_module_to_txt_map_filename(),
                 delimiter=':',
                 what="module name to .txt map"))
     return self.__module_to_txt_map
Exemplo n.º 2
0
 def __init__(self,
              file_dependencies,
              file_to_module_map,
              use_transitive_closure=True,
              module_name_filter=lambda module: module):
     if use_transitive_closure:
         unique_file_dependencies = set(
             (src, dst) for (src, dst) in file_dependencies)
         self.__reverse_file_dependencies = SetValuedDictTools.convert_from_itemiterator(
             (target, source)
             for (source, target) in GraphAlgorithms.transitive_closure(
                 unique_file_dependencies))
     else:
         self.__reverse_file_dependencies = SetValuedDictTools.convert_from_itemiterator(
             (target, source) for (source, target) in file_dependencies)
     self.__target_files_to_referencing_modules_map = dict()
     self.__files_to_modules_raw = dict(file_to_module_map)
     self.__module_name_filter = module_name_filter
Exemplo n.º 3
0
 def convert_module_list_to_file_list(moduleDependencies):
     """
     Converts a module-to-set(file)-dictionary to a file-to-set(module)-dictionary.
     
     >>> pprint.pprint(LocalCollectionTools.convert_module_list_to_file_list({'x': set(['a', 'b']), 'y': set(['c'])}))
     {'a': set(['x']), 'b': set(['x']), 'c': set(['y'])}
     
     >>> print_dependencies(CommaSeparationTools.value_set_to_csv(LocalCollectionTools.convert_module_list_to_file_list({'x': set(['a', 'b']), 'y': set(['c'])})))
     a = x
     b = x
     c = y
     """
     return SetValuedDictTools.transpose(moduleDependencies)
Exemplo n.º 4
0
 def join_modules(dependencies, targetModule, sourceModules):
     """
     Joins the specified source modules in the list of dependencies into the target module, 
     which may or may not exist previously.
     
     >>> BasicOperations.join_modules({}, 'x', ['y'])
     {}
 
     >>> pprint.pprint(BasicOperations.join_modules({'x': set(['a', 'b']), 'y': set(['c'])}, 'x', ['y']))
     {'x': set(['a', 'b', 'c'])}
     
     >>> pprint.pprint(BasicOperations.join_modules({'x': set(['a', 'b']), 'y': set(['c'])}, 'x', ['y']))
     {'x': set(['a', 'b', 'c'])}
     
     >>> pprint.pprint(BasicOperations.join_modules({'x': set(['a', 'b']), 'y': set(['c'])}, 'x', ['z']))
     {'x': set(['a', 'b']), 'y': set(['c'])}
     
     >>> pprint.pprint(BasicOperations.join_modules({frozenset(['x']): set(['a', 'b']), frozenset(['y']): set(['c'])}, frozenset(['x']), [frozenset(['z'])]))
     {frozenset(['y']): set(['c']), frozenset(['x']): set(['a', 'b'])}
     """
     return SetValuedDictTools.join_keys(dependencies, targetModule, sourceModules)
def main():
    logging.basicConfig(stream=sys.stderr, level=logging.INFO)
    Configurator().default()

    vcproj_lines = config_msvc_data_supply().get_vcproj_list()
    dirs_to_vcprojs_map = SetValuedDictTools.convert_from_itemiterator(
        (os.path.dirname(line[0]), line[0]) for line in vcproj_lines)
    os.chdir(config_cpp_paths.get_module_spec_basedir())
    mapper = VcprojToModuleNameMapper()
    for (dirname, vcprojs) in sorted(dirs_to_vcprojs_map.iteritems()):
        if dirname == '':
            # this is an entry containing solution folders, not projects # TODO this should be filtered somewhere else
            continue
        if len(vcprojs) == 1:
            top_vcproj = vcprojs.pop()
        else:
            top_vcproj = max(vcprojs, key=lambda name: os.stat(name).st_size)

        # TODO this has not the correct case... better: extract module name from vcproj file
        # das ist doch schon gefixed, oder nicht??
        if len(dirname):
            print "%s:%s" % (dirname, mapper.get_module_name(top_vcproj))
Exemplo n.º 6
0
    def check_links(self, file_links, checkers):
        """
        
        @param file_links:
        @type file_links: iterable of tuples of minimum length 2, whose first two elements are two file paths denoting an include relationship
        @param checkers: 
        @type checkers: collection of IncludeRuleChecker instances
        
        @rtype: a 3-tuple containing 
            1. a dictionary mapping dependencies to a list of names of violating rules
            2. total count of input items
            3. a dictionary mapping names of violations rules to number of total violations 
        """
        illegal_links = list()
        total_count = 0

        rule_violations = dict()
        for checker in checkers:
            rule_violations[checker.get_rule_name()] = 0
        rule_violations[self.UNKNOWN_PATH_PSEUDO_RULE_NAME] = 0
        for line in file_links:
            if len(line) < 2:
                self.__logger.warning("Illegal input item %s" % line)
            else:
                (from_file, to_file) = line[0:2]
                total_count += 1
                try:
                    for checker in checkers:
                        if not checker.is_legal_dependency(from_file, to_file):
                            rule_name = checker.get_rule_name()
                            illegal_links.append(
                                ((from_file, to_file), rule_name))
                            rule_violations[rule_name] += 1
                except UnknownPath:
                    illegal_links.append(((from_file, to_file),
                                          self.UNKNOWN_PATH_PSEUDO_RULE_NAME))
                    rule_violations[self.UNKNOWN_PATH_PSEUDO_RULE_NAME] += 1
        return SetValuedDictTools.convert_from_itemiterator(
            illegal_links), total_count, rule_violations
Exemplo n.º 7
0
    def process(self, args):
        parser = self.__create_option_parser()
        (options, args) = parser.parse_args(args=args)

        if options.all:
            self.__output(module_list_supply=self.__module_list_supply,
                          html=options.output_html)

        if options.duplicates:
            if hasattr(config_module_list_supply, "get_module_descriptors"):
                print "Duplicate module names:"
                name_to_descriptors = SetValuedDictTools.convert_from_itemiterator(
                    (y, x)
                    for (x,
                         y) in self.get_module_list(self.__module_list_supply))
                for (module_name,
                     descriptor_files) in name_to_descriptors.iteritems():
                    if len(descriptor_files) > 1:
                        print module_name

        if options.unreferenced:
            self.__output(module_list_supply=UnreferencedModuleListSupply(
                module_list_supply=self.__module_list_supply),
                          html=options.output_html)
Exemplo n.º 8
0
 def __create_filemap(self, paths):
     items = chain.from_iterable(
         ((os.path.basename(filename), filename)
          for filename in self.__filelists.get_filelist(basepath))
         for basepath in paths)
     return SetValuedDictTools.convert_from_itemiterator(items)