Beispiel #1
0
 def _check_and_add(self, filename):
     if not os.path.exists(filename):
         if os.path.islink(filename):
             p_warn("Warning: ignoring broken sym link - (%s)" % filename)
             return
         else:
             raise CheckfortException("Invalid path - " + filename)
     assert(not os.path.isdir(filename))
     self.files.append(os.path.relpath(filename))
Beispiel #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])
Beispiel #3
0
def main():
    o, a = parse_options()

    cleaned = {}  # store validated input options
    cleaned["outdir"] = o.outdir
    cleaned["pretend"] = bool(o.pretend)
    cleaned["extra_opts"] = shlex.split(o.extra_opts or "")

    # --compiler-emulation can only be checked once Forcheck is found.
    # Accept anything for now
    cleaned["emulation"] = o.emulation

    # Set log level
    if o.quiet or cleaned["pretend"]:
        set_silent_mode()
    elif o.verbose:
        set_verbose_mode()
    if o.debug:
        set_debug_mode()

    # Once output verbosity set, we can print the output header
    p_info("%s" % header)

    # check allowed standards
    if o.standard not in supported_standards:
        p_error("Unsupported fortran standard (%s). Options: %s"
                % (o.standard, ", ".join(supported_standards)))
    else:
        cleaned["standard"] = o.standard

    # deal with optional --free-form
    if o.free_form:
        if cleaned["standard"] == '77':
            p_warn("Fortran 77 does not support free format. Ignoring "
                   "--free-form (-f) option.")
            o.free_form = False
    cleaned["free_format"] = bool(o.free_form)

    # check --ignore-err-codes (must be comma separated numeric codes)
    try:
        cleaned["ignore_list"] = list(set(int(x) for x in o.ignore.split(",")
                                                     if x.strip()))
    except ValueError:
        p_error("Invalid value for --ignore-err-codes (-i). "
                "Expecting comma-separated list of numeric values")

    # read target files form positional args and --input-file option
    targets = a[:]  # get targets from arguments
    if o.input_file:  # get targets from file specified with --input-file
        try:
            targets.extend(InputFileReader(o.input_file).get_entries())
        except IOError:
            p_error("Input file not readable: %s" % o.input_file)
    if not targets:
        p_error("No inputs provided.")

    # file extensions to search for
    if o.extensions:
        ext_list = [x.strip() for x in o.extensions.split(",")]
    else:
        ext_list = default_extensions

    # search and validate target files
    if any(os.path.isdir(x) for x in targets):
        p_info("Searching directories for files with the following "
                  "extensions : %s" % " ".join("*.%s" % x for x in ext_list))
    try:
        filelist = FileList(targets,  ext_list)
    except CheckfortException, e:
        p_error(e)