Exemplo n.º 1
0
    def _gen_source_pages(self):
        p_info(" - Generating marked-up source files")
        ctx = self.default_context.copy()
        for filename, event_instances in self.state.file_events.iteritems():
            ctx["code_block"], subpath, depth = self._format_source(filename)
            outfile = os.path.join(self.outdir, subpath)
            p_verbose("   -- %s" % outfile)

            ctx["to_root"] = "../" * depth
            ctx["filename"] = filename
            outdir = os.path.dirname(outfile)
            if outdir and not os.path.isdir(outdir):
                os.makedirs(outdir)

            with open(outfile, 'w') as f:
                f.write(render("code_source.html", ctx).encode('utf-8'))
Exemplo n.º 2
0
    def _report_runtime_message(self, line):
        """Selectively print content from forcheck runtime output"""
        line = line.strip()

        if line.startswith("-- "):
            if line.startswith("-- file: "):
                p_verbose("    - %s" % line.split(None, 2)[2])
            elif not line.startswith("-- commandline") and \
                    not line.startswith("-- messages presented"):
                p_verbose(line)
            if not verbose_enabled():
                p_info(".", "")

        elif line.startswith("FCK-- "):
            err = line.split(None, 1)[1]
            culprit, filename = self._store_prev
            if not filename.startswith("("):
                filename = ""  # not specified
            p_warn("%s - %s %s\n" % (err, culprit, filename))

        elif not verbose_enabled() and line.startswith("- file"):
            p_info(".", "")

        self._store_prev = (line, self._store_prev[0])
Exemplo n.º 3
0
    def _parse(self):
        p_info("\nParsing forcheck listfile")
        if self.state.ignore_list:
            p_info("(ignoring the following forcheck events: "
                   "%s)" % ", ".join(str(x) for x in self.state.ignore_list))

        stages = iter((
            {"name": "file events",
             "end_marker": "global program analysis:",
             "parser": FileEvent(self.state)},
            {"name": "global events",
             "end_marker": "program_units and procedures analysed:",
             "parser": GlobalEvent(self.state)},
            {"name": "program units",
             # "end_marker": "*END OF ANALYSIS*"  # no longer appear in >14.3
             "end_marker": "messages presented:",
             "parser": None},
            {"name": "forcheck summary",
             "end_marker": None,
             "parser": SummaryEvent(self.state)},
        ))

        lines = ("", "", "")  # (current, previous, previous-1)
        stage = stages.next()
        p_info(" - Parsing %s" % stage["name"])

        def forward_to_content(file_iterator):
            """
            Forwards file iterator the the actual content, then returns
            the source file addressed by forcheck output page
            """
            # each new page starts with a header
            line = next(file_iterator)
            assert line.startswith("FORCHECK"), "Unexpected listfile format"

            # this is followed by "(options...) target_file" if the output is
            # file specific
            line = next(file_iterator)
            if line.strip():
                target_file = line.rsplit(None, 1)[-1]
                line = next(file_iterator)  # following line should be blank
                assert not line.strip(), "Unexpected listfile format"
            else:
                target_file = None
            return target_file

        with open(self.listfile) as f:
            target_file = forward_to_content(f)
            for L in f:
                if L.startswith("\f"):  # new page. forward to content
                    target_file = forward_to_content(f)
                    continue
                lines = (L.strip(), lines[0], lines[1])  # shift
                if lines[0] == stage["end_marker"]:
                    stage = stages.next()
                    p_info(" - Parsing %s" % stage["name"])
                elif stage["parser"]:  # if event has a parser
                    stage["parser"].slurp(target_file, *lines)

        if self.state.debug_required:
            import shutil
            listfile_out = "forcheck_listfile.debug"
            shutil.copy(self.listfile, listfile_out)
            p_debug(
                "There appears to be a problem in the parsing. \n"
                " Forcheck results written to %s. \n"
                " Please send the file and the checkfort version info\n"
                "    to the checkfort devs for further investigation"
                % (listfile_out, ))
        else:
            p_verbose("Parse successful")
Exemplo n.º 4
0
 def _search_dir(self, directory):
     p_verbose(" - Searching for files in %s" % directory)
     for root, dirs, files in os.walk(os.path.relpath(directory)):
         for f in files:
             if self.re_extensions.match(f):
                 self._check_and_add(os.path.join(root, f))