コード例 #1
0
 def get_path(configparser, configvar, default=None):
     raw_directory = configparser.get(configvar, default)
     if PathTools.is_cygwin_directory(raw_directory):
         return PathTools.cygwin_to_cmd_path(raw_directory)
     else:
         return os.path.normcase(
             os.path.normpath(os.path.normcase(raw_directory)))
コード例 #2
0
 def __include_parameter_internal(self, include_path_rel_to_root,
                                  repair_path):
     if self.__include_paths_rel_to_root:
         include_path = include_path_rel_to_root
     else:
         include_path = PathTools.relative_path(include_path_rel_to_root,
                                                repair_path)
     return PathTools.unix_normpath(include_path)
コード例 #3
0
 def output_all(self):
     stylesheet_path = PathTools.native_to_posix(
         os.path.join(
             compatrelpath(config_basic.get_results_directory(),
                           os.path.dirname(self.file().name)),
             'styles.css'))
     print >> self.file(), HTMLHelper.get_html_head(
         title=self.description(),
         charset='iso-8859-1',
         stylesheet=stylesheet_path,
     )
     print >> self.file(), HTMLHelper.get_preamble()
     print >> self.file(), """
     <h1>BTC RevEngTools Results: %s</h1>
     <h2>System: %s, Version: %s, Repository revision: %s</h2>
     <h2>Analysis time: %s</h2>
     
     """ % (
         self.description(),
         # TODO hierfür sollten die Graph Decorator verwendet werden
         config_basic.get_system(),
         config_basic.get_version(),
         FallbackVersionDescriber(
             config_version_describer).describe_local_version(
                 config_basic.get_local_source_base_dir(), False)[2],
         datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S"))
     self.__table_output.output_all()
     print >> self.file(), HTMLHelper.get_postamble()
     print >> self.file(), HTMLHelper.get_html_tail()
コード例 #4
0
 def process_file(self, repair_path_name):
     """
     @return: 
     @rtype: iterator (or set?) of strings
     """
     
     repair_path_rel_to_root_unix = PathTools.unix_normpath(repair_path_name)
     if not self.is_local_file(repair_path_rel_to_root_unix):
         self.__logger.info("Ignoring non-local file %s" % (repair_path_rel_to_root_unix, ))
         return []
     try:
         repair_resource = self.__resource_resolver.resolve(repair_path_rel_to_root_unix)
     
         self.__logger.info("Processing %s" % (repair_path_rel_to_root_unix, ))
         required_include_files = self.__generation_strategy.process(repair_resource, 
                                                                     lambda input_resource, output_resource: self.__generate(repair_path_rel_to_root_unix, input_resource, output_resource))
                             
         # TODO nur die lokalen Header zur�ck liefern
         self.__successful_files.append(repair_path_rel_to_root_unix)
         return required_include_files
     except ManualProcessingException:
         self.__skipped_files.append(repair_path_rel_to_root_unix)
         self.__logger.info("Using manual includes in %s, skipping file" % (repair_path_rel_to_root_unix,))
         return []
     except FileTransformationException:
         self.__error_files.append(repair_path_rel_to_root_unix)
         self.__logger.warning("Error while processing %s, skipping file" % (repair_path_rel_to_root_unix,), exc_info=1)
         return []
     except:
         self.__logger.warning("Fatal error while processing %s, skipping file" % (repair_path_rel_to_root_unix,), exc_info=1)
         self.__fatal_files.append(repair_path_rel_to_root_unix)
         return []
コード例 #5
0
 def format_include_map(local_source_base_dir, include_map_items):
     for base_path, include_specifications in include_map_items:
         for _include_specification_type, included_resource in include_specifications:
             included_path = included_resource.name()
             if included_path.startswith(local_source_base_dir + os.path.sep):
                 included_path = PathTools.native_to_posix(included_path.split(local_source_base_dir + os.path.sep)[1])
             yield "%s,%s" % (base_path, included_path)    
コード例 #6
0
    def __get_include_specification_for_include_directive_line(self, line):
        parts = PreprocessorConstants.INCLUDE_DIRECTIVE_REGEX.split(line)
        if len(parts) != 2:
            msg = "Unprocessable line in file %s: %s" % (self.__repair_path,
                                                         line)
            self.__logger.warning(msg)
            raise IDNValueError(msg)
        raw_include_specification = parts[1].strip()
        match_quoted = PreprocessorConstants.REGEX_INCLUDE_SPECIFICATION_QUOTED.match(
            raw_include_specification)
        if match_quoted and len(match_quoted.groups()) == 1:
            included_file = match_quoted.group(1)
            match_type = IncludeSpecificationTypes.QUOTED
        else:
            match_angle = PreprocessorConstants.REGEX_INCLUDE_SPECIFICATION_ANGLE.match(
                raw_include_specification)
            if match_angle and len(match_angle.groups()) == 1:
                included_file = match_angle.group(1)
                match_type = IncludeSpecificationTypes.ANGLE
            else:
                msg = "Ignoring unparsable line in file %s: %s" % (
                    self.__repair_path, line)
                self.__logger.warning(msg)
                self.__count_unparsable += 1
                raise IDNValueError(msg)

    #included_file = PathTools.unix_normpath(included_file)
        return self.__include_resolver.resolve_include_specification(
            PathTools.native_to_posix(included_file),
            try_first=(os.path.normpath(
                os.path.join(self.__repair_project_file.get_resource().name(),
                             os.path.pardir, included_file)), )
            if match_type == IncludeSpecificationTypes.QUOTED else ())
コード例 #7
0
    def output(self, output_file, illegal_links, total_count, rule_violations):
        print >> output_file, "Illegal include links:"
        for (from_file,
             to_file), violations in sorted(illegal_links.iteritems()):
            print >> output_file, "%s -> %s (%s)" % (
                PathTools.unix_normpath(from_file),
                PathTools.unix_normpath(to_file), ", ".join(violations))

        print >> output_file, ("%i total links, %i illegal links" %
                               (total_count, len(illegal_links)))

        if len(illegal_links):
            print >> output_file, "Violations by rule:",
            print >> output_file, ", ".join(
                "%s=%i" % (name, count)
                for name, count in rule_violations.iteritems())
コード例 #8
0
ファイル: csproj_parser.py プロジェクト: sigiesec/revengtools
 def get_source_files(self):
     if not self.__path_resolver:
         raise RuntimeError("No path resolver set")
     elements = self.__dom.getElementsByTagNameNS(VSConstants.NAMESPACE_URI, "Compile")
     for element in elements:
         filename = element.getAttribute("Include")
         yield self.__path_resolver.resolve(PathTools.windows_to_native(filename))
コード例 #9
0
ファイル: file_supply.py プロジェクト: sigiesec/revengtools
 def __check(self, module_name, fullname):
     if module_name in self.CHECK_EXCEPTIONS:
         return ()
     try:
         specfile_path = self.get_cmakelists_file(module_name)
     except:
         specfile_path = fullname
     specfile_dir_transformed = os.path.dirname(
         specfile_path.replace(posixpath.sep, os.path.sep))
     #Nina wants to have some feedback in the console to see the process is still alive
     print >> sys.stderr, "parsing %s" % (fullname)
     # the directory of the .vcproj does not matter for cmake-generated files, since it might be generated into a mangled directory name to avoid paths that are too long
     module_files = list(self.get_files_for_module(module_name))
     common_base_dir = PathTools.common_base_directory(module_files)
     data = dict({
         ModuleCheckerParameterKeys.ANALYSIS_BASE_DIRS:
         self.__analysis_base_dirs,
         ModuleCheckerParameterKeys.BINARY_BASENAME:
         module_name,
         ModuleCheckerParameterKeys.MODULE_SPECIFICATION_FILE_DIRNAME:
         self.__get_relative_name(specfile_dir_transformed),
         ModuleCheckerParameterKeys.SOURCE_ROOT_DIRNAME:
         self.__trim_after(self.__get_relative_name(common_base_dir), "src")
         if common_base_dir else None,
         ModuleCheckerParameterKeys.MODULE_SPECIFICATION_FILE_BASENAME:
         self.__get_filename(specfile_path),
         ModuleCheckerParameterKeys.SOURCE_FILES:
         module_files,
         #ModuleCheckerParameterKeys.ROOT_NAMESPACE: root_namespace,
     })
     self.__logger.info("Module Data for %s: " % fullname + str(data))
     self.__module_checker_parameter[fullname] = data
コード例 #10
0
 def generate_for_input_files_in_dir(self, directory, input_files, outfile):
     input_files = list(input_files)
     if len(input_files) == 0:
         self.__logger.warning("No input files for directory %s", directory)
         return
     cmdline = self._get_cmdline(directory, input_files)
     if len(cmdline) + sum(map(len, cmdline)) > 8190:
         self.__logger.info("cmdline too long, splitting for directory %s" %
                            (directory, ))
         two_halves = self.split_into_two_halves(input_files)
         for portion in two_halves:
             self.generate_for_input_files_in_dir(directory, portion,
                                                  outfile)
     else:
         self.__logger.debug("%s: calling %s",
                             threading.currentThread().name, cmdline)
         if False:
             cmdline = [
                 'D:\\cygwin\\bin\\bash.exe', "--login", "-c",
                 "cd %s" % (posixpath.join(
                     config_basic.get_local_source_base_dir().replace(
                         "\\", "/"), directory)), "-c",
                 " ".join(PathTools.native_to_posix(x) for x in cmdline)
             ]
         retval = subprocess.call(cmdline, stdout=outfile)
         self.__logger.debug("%s: return value is %x",
                             threading.currentThread().name, retval)
         if retval not in [0, 255]:
             raise CalledProcessError(retval, cmdline)
コード例 #11
0
 def __normalize_include_line(self, line):
     try:
         (include_specification_type, canonical_resource
          ) = self.__get_include_specification_for_include_directive_line(
              line)
         parts = PreprocessorConstants.INCLUDE_DIRECTIVE_REGEX.split(line)
         canonical_path = PathTools.unix_normpath(
             PathTools.resource_to_relpath(canonical_resource))
         include_specification = self.__get_template(
             include_specification_type) % (canonical_path)
         # TODO restrict this to internal files
         self.__included_files.append(canonical_path)
         return "%s%s %s\n" % (parts[0],
                               PreprocessorConstants.INCLUDE_DIRECTIVE,
                               include_specification)
     except IDNValueError:
         return line
コード例 #12
0
ファイル: file_supply.py プロジェクト: sigiesec/revengtools
 def get_cmakelists_file(self, module_name):
     cmakelists = filter(
         lambda x: posixpath.basename(x).lower() == 'CMakeLists.txt'.lower(
         ),
         self.__get_module_to_txt_map()[module_name])
     if len(cmakelists) != 1:
         msg = "No or multiple CMakeLists.txt found for module %s: %s" % (
             module_name, cmakelists)
         raise ValueError(msg)
     return PathTools.canonicalize_capitalization(
         self.__project_dir_resolver.resolve(cmakelists[0]).name())
コード例 #13
0
ファイル: header_linker.py プロジェクト: sigiesec/revengtools
    def cpp_filename_new(header_filename):
        """
        >>> PRINSTools.cpp_filename_new('processvariable/eventtracerclient/include/client.h')
        'processvariable/eventtracerclient/src/client.cpp'

        >>> PRINSTools.cpp_filename_new('__prio4/_dyn/foo.h') == None
        True
        """
        # TODO assert that header_filename is a posixpath?
        header_dirname = posixpath.dirname(header_filename)
        if posixpath.basename(header_dirname) == 'include':
            return posixpath.join(posixpath.dirname(header_dirname),
                                  'src',
                                  PathTools.replace_extension(posixpath.basename(header_filename), '.cpp')
                                 )
        else:
            return None
コード例 #14
0
ファイル: cpp_util.py プロジェクト: sigiesec/revengtools
 def scan_project_files(base_dirs, local_source_base_dir,
                        cpp_file_configuration, logger):
     extensions = tuple(
         [] + cpp_file_configuration.get_implementation_file_extensions() +
         cpp_file_configuration.get_header_file_extensions())
     #self.__logger.log(logging.INFO, "Scanning files with extensions %s in %s recursively" % (extensions, base_dirs))
     abs_paths = chain.from_iterable(
         (WalkTools.walk_extensions(onerror=logger.warning,
                                    extensions=extensions,
                                    top=path,
                                    skip_dirs=[".svn"]) if os.path.
          isdir(path) else ((
              path, ) if os.path.exists(path) else call_and_return(
                  lambda: logger.warning("%s does not exist" % path), ())))
         for path in imap(
             lambda rel_path: os.path.join(local_source_base_dir, rel_path),
             base_dirs))
     files = (PathTools.relative_path(
         path_name=abs_path,
         relative_to=local_source_base_dir + os.path.sep,
         ignore_absolute=False) for abs_path in abs_paths)
     return list(files)
コード例 #15
0
 def resolve_include_specification(self, included_file, try_first):
     """
     @rtype: tuple(IncludeSpecificationType, Resource)
     """
     try:
         (include_specification_type, canonical_resource
          ) = self.__include_path_canonicalizer.canonicalize(
              included_file, try_first)
         self.__count_resolvable[include_specification_type] += 1
         return (include_specification_type, canonical_resource)
     except ResourceUnresolvable:
         self.__logger.warning(
             "Include file %s in file %s cannot be resolved exactly" %
             (included_file, self.__repair_path))
         self.__logger.debug("Cause", exc_info=1)
         self.__count_unresolvable += 1
         fuzzy_result = self.__fuzzy_resolver_func(included_file)
         if fuzzy_result:
             self.__count_fuzzy += 1
             return fuzzy_result
         else:
             return (IncludeSpecificationTypes.ANGLE,
                     FileResource(
                         path=PathTools.unix_normpath(included_file)))
コード例 #16
0
 def __get_url_for_node(self, node):
     abspath = self._get_abspath_for_node(node)
     return PathTools.get_url_for_local_path(abspath)
コード例 #17
0
 def server_to_rel_to_root_path(self, server_path):
     return PathTools.unix_normpath(
         config_path_tools.server_to_relative_path(server_path))
コード例 #18
0
ファイル: csproj_parser.py プロジェクト: sigiesec/revengtools
 def __parse_project_reference_name(self, pr_element):
     # TODO this is not very clean. the project reference proxy should use the resource, not its name... 
     return ProjectReferenceProxy(self.__path_resolver.resolve(PathTools.windows_to_native(pr_element.getAttribute("Include"))))