Beispiel #1
0
 def _resolve_fuzzy(self, to_module):
     file_basename = StringTools.strip_suffix(os.path.basename(
         to_module.get_resource().name()),
                                              VSConstants.VCXProj_EXTENSION,
                                              ignore_case=True)
     candidates = list(
         filename
         for (filename,
              modulename) in self.__file_to_module_name_map.iteritems()
         if modulename == file_basename
         or os.path.basename(filename) == file_basename)
     candidates = sorted(
         candidates, key=lambda x: -len(self.__file_to_module_name_map[x]))
     if len(candidates):
         if len(candidates) > 1:
             self.__logger.warning(
                 "Could not resolve project reference to %s exactly, but multiple fuzzy matches could be found in %s, using %s"
                 % (to_module.get_resource().name(), ", ".join(candidates),
                    candidates[0]))
         else:
             self.__logger.warning(
                 "Could not resolve project reference to %s exactly, but a fuzzy match could be found in %s"
                 % (to_module.get_resource().name(), candidates[0]))
         return self.__file_to_module_name_map[candidates[0]]
     return None
Beispiel #2
0
 def __to_rel_to_project_root_path(self, abspath):
     """
     Converts an absolute path to a path relative to the project's base path.
     
     @param abspath: an absolute path
     @type abspath: basestring
     
     @rtype: str or unicode (depending on type(abspath))        
     """
     # TODO this should use self.__project_dir_resolver instead, since BasicConfig.get_local_source_base_dir() is deprecated
     # TODO a utility function should be added to commons.os_util which does this in general for an absolute path and a LocalPathResolver
     # TODO is it guaranteed that the string returned by get_local_source_base_dir never ends with os.path.sep?  
     return StringTools.strip_prefix(abspath, self.__basic_config.get_local_source_base_dir() + os.path.sep)
 def __init__(self,
              file_to_module_map,
              modules,
              local_output_aggregate_for_individual_func,
              optimiseNodeNames=False,
              optimiseModuleNames=True,
              get_raw_modulename=lambda x: x):
     self.__selected_input_aggregates = modules
     self.__individual_to_input_aggregate_map = file_to_module_map
     self.__local_output_aggregate_to_input_aggregate_map = None
     self.__filter_input_aggregate_func = get_raw_modulename
     self.__local_output_aggregate_for_individual_func = local_output_aggregate_for_individual_func
     if optimiseNodeNames and len(self.__selected_input_aggregates) > 1:
         self.__local_output_aggregate_to_input_aggregate_map = \
             dict(self.__local_output_aggregate_to_input_aggregate_iteritems())
     if optimiseModuleNames:
         self.__selected_input_aggregates_common_prefix, self.__optimised_input_aggregates = \
             StringTools.prefix_optimise(self.__selected_input_aggregates)
     else:
         self.__optimised_input_aggregates = dict()
         self.__selected_input_aggregates_common_prefix = ""
 def _do_task(self, executable, filename, result, resultlock, binary_util):
     self.__logger.debug("Worker %s processes file %s",
                         threading.currentThread().name, filename)
     cmdline = (executable, filename)
     process = subprocess.Popen(cmdline, stdout=subprocess.PIPE, bufsize=1)
     mapper = lambda filename: StringTools.strip_suffixes(
         os.path.basename(filename.strip()),
         binary_util.get_binary_extensions(),
         ignore_case=True)
     self.__process_data(filename,
                         result,
                         resultlock,
                         mapper,
                         stream=process.stdout)
     process.wait()
     self.__logger.debug("%s: return value is %x",
                         threading.currentThread().name, process.returncode)
     if process.returncode not in [0, 255]:
         raise CalledProcessError(process.returncode, cmdline)
     self.__logger.debug("Worker %s finished processing directory %s",
                         threading.currentThread().name, filename)
     self.__logger.debug("Remaining threads: %s", threading.enumerate())
Beispiel #5
0
 def test_strip_all_prefixes_4(self):
     self.assertEquals('abcd', StringTools.strip_all_prefixes('abcd', []))
Beispiel #6
0
 def test_strip_all_prefixes_1(self):
     self.assertEquals('', StringTools.strip_all_prefixes('abcd', ['d', 'c', 'b', 'a']))
Beispiel #7
0
 def test_strip_first_prefix_2(self):
     self.assertEquals('bcd', StringTools.strip_first_prefix('abcd', ['a', 'b', 'c', 'd']))
Beispiel #8
0
 def test_strip_all_suffixes_4(self):
     self.assertEquals('abcd', StringTools.strip_all_suffixes('abcd', ['a', 'b', 'c']))
Beispiel #9
0
 def test_strip_first_suffix_3(self):
     self.assertEquals('', StringTools.strip_first_suffix('', ['a', 'b', 'c', 'd']))
Beispiel #10
0
 def test_strip_suffix_6(self):
     self.assertEquals('', StringTools.strip_suffix("", ""))
Beispiel #11
0
 def test_get_common_prefix_3(self):
     self.assertEquals('', StringTools.get_common_prefix(('dyn', 'prio4dyn', 'prid4dyn')))
Beispiel #12
0
 def test_get_common_prefix_2(self):
     self.assertEquals('', StringTools.get_common_prefix(set(('ABC', 'ABCD', 'ABCE', 'XYZ'))))
Beispiel #13
0
 def test_get_common_prefix_1(self):
     self.assertEquals('ABC', StringTools.get_common_prefix(iter(('ABC', 'ABCD', 'ABCE'))))
Beispiel #14
0
 def test_get_common_prefix_len_7(self):
     self.assertEquals(1, StringTools.get_common_prefix_len('ab', 'aB'))
Beispiel #15
0
 def filename_to_cpp_pseudomodule_func(cpp_extensions):
     return lambda filename: StringTools.strip_suffixes(
         os.path.basename(filename), cpp_extensions)
Beispiel #16
0
 def test_strip_suffix_2(self):
     self.assertEquals('a', StringTools.strip_suffix("abcd", "BCD", ignore_case=True))
Beispiel #17
0
 def test_strip_suffix_5(self):
     self.assertEquals('abcd', StringTools.strip_suffix("abcd", ""))
Beispiel #18
0
 def test_get_common_prefix_4(self):
     self.assertEquals('', StringTools.get_common_prefix(('A', 'B')))
Beispiel #19
0
 def test_strip_first_suffix_1(self):
     self.assertEquals('abc', StringTools.strip_first_suffix('abcd', ['d', 'c', 'b', 'a']))
Beispiel #20
0
 def test_get_common_prefix_5(self):
     self.assertEquals(None, StringTools.get_common_prefix(()))
Beispiel #21
0
 def test_strip_first_suffix_non_fitting(self):
     self.assertEquals('abcd',StringTools.strip_first_suffix('abcd',['e','f','g','h']))
Beispiel #22
0
 def test_get_common_prefix_6(self):
     self.assertEquals((1, 2, 3), StringTools.get_common_prefix(((1,2,3),(1,2,3,4))))
Beispiel #23
0
 def test_strip_all_suffixes_none(self):
     self.assertEquals('abcd', StringTools.strip_all_suffixes('abcd', []))
Beispiel #24
0
 def test_optimise_prefix_strings(self):
     (prefix, optimised_map) = StringTools.prefix_optimise(("ABCD", "ABCE"))
     self.assertEquals('ABC', prefix)
     self.assertEquals([('ABCD', 'D'), ('ABCE', 'E')], sorted(optimised_map.iteritems()))
Beispiel #25
0
 def test_strip_first_prefix_none(self):
     self.assertEquals('abcd', StringTools.strip_first_prefix('abcd', []))
Beispiel #26
0
 def test_strip_suffix_1(self):
     self.assertEquals('abcd', StringTools.strip_suffix("abcd", "BCD", ignore_case=False))
Beispiel #27
0
 def test_strip_all_prefixes_3(self):
     self.assertEquals('cd', StringTools.strip_all_prefixes('abcd', ['a', 'b', 'd']))
Beispiel #28
0
 def test_optimise_prefix_tuples(self):
     (prefix, optimised_map) = StringTools.prefix_optimise(((1, 2, 3), (1, 2, 4)))
     self.assertEquals((1,2), prefix)
     self.assertEquals([((1, 2, 3), (3,)), ((1, 2, 4), (4,))], sorted(optimised_map.iteritems()))
Beispiel #29
0
 def test_get_common_prefix_len_2(self):
     self.assertEquals(0, StringTools.get_common_prefix_len('a', ''))
Beispiel #30
0
 def test_optimise_prefix_strings_null(self):
     (prefix, optimised_map) = StringTools.prefix_optimise(("ABCD", "XYZ"))
     self.assertEquals('', prefix)
     self.assertEquals([('ABCD', 'ABCD'), ('XYZ', 'XYZ')], sorted(optimised_map.iteritems()))