コード例 #1
0
def clean_capgen(cap_output_file, logger):
    ###############################################################################
    """Attempt to remove the files created by the last invocation of capgen"""
    log_level = logger.getEffectiveLevel()
    set_log_level(logger, logging.INFO)
    if os.path.exists(cap_output_file):
        logger.info("Cleaning capgen files from {}".format(cap_output_file))
        delete_pathnames_from_file(cap_output_file, logger)
    else:
        emsg = "Unable to run clean, {} not found"
        logger.error(emsg.format(cap_output_file))
    # end if
    set_log_level(logger, log_level)
コード例 #2
0
def main():
    # Initialize logging
    logger = init_log('metadata2html')
    set_log_level(logger, logging.INFO)
    # Convert metadata file
    (configfile, filename, outdir) = parse_arguments()
    if configfile:
        config = import_config(configfile, logger)
        filenames = get_metadata_files_from_config(config, logger)
        outdir = get_output_directory_from_config(config, logger)
        for filename in filenames:
            convert_to_html(filename, outdir, logger)
    else:
        convert_to_html(filename, outdir, logger)
コード例 #3
0
def _main_func():
    ###############################################################################
    """Parse command line, then parse indicated host, scheme, and suite files.
    Finally, generate code to allow host model to run indicated CCPP suites."""
    framework_env = parse_command_line(sys.argv[1:], __doc__, logger=_LOGGER)
    if framework_env.verbosity > 1:
        set_log_level(framework_env.logger, logging.DEBUG)
    elif framework_env.verbosity > 0:
        set_log_level(framework_env.logger, logging.INFO)
    # end if
    if framework_env.clean:
        clean_capgen(framework_env.datatable_file, framework_env.logger)
    else:
        capgen(framework_env)
コード例 #4
0
def _main_func():
    ###############################################################################
    """Parse command line, then parse indicated host, scheme, and suite files.
    Finally, generate code to allow host model to run indicated CCPP suites."""
    args = parse_command_line(sys.argv[1:], __doc__)
    verbosity = args.verbose
    if verbosity > 1:
        set_log_level(_LOGGER, logging.DEBUG)
    elif verbosity > 0:
        set_log_level(_LOGGER, logging.INFO)
    # end if
    # Make sure we know where output is going
    output_dir = os.path.abspath(args.output_root)
    if os.path.abspath(args.ccpp_datafile):
        datatable_file = args.ccpp_datafile
    else:
        datatable_file = os.path.abspath(
            os.path.join(output_dir, args.ccpp_datafile))
    # end if
    ## A few sanity checks
    ## Make sure output directory is legit
    if os.path.exists(output_dir):
        if not os.path.isdir(output_dir):
            errmsg = "output-root, '{}', is not a directory"
            raise CCPPError(errmsg.format(args.output_root))
        # end if
        if not os.access(output_dir, os.W_OK):
            errmsg = "Cannot write files to output-root ({})"
            raise CCPPError(errmsg.format(args.output_root))
        # end if (output_dir is okay)
    else:
        # Try to create output_dir (let it crash if it fails)
        os.makedirs(output_dir)
    # end if
    # Make sure we can create output file lists
    if not os.path.isabs(datatable_file):
        datatable_file = os.path.normpath(
            os.path.join(output_dir, datatable_file))
    # end if
    if args.clean:
        clean_capgen(datatable_file, _LOGGER)
    else:
        generate_host_cap = args.host_name != ''
        preproc_defs = args.preproc_directives
        capgen(args.host_files, args.scheme_files, args.suites, datatable_file,
               preproc_defs, generate_host_cap, args.generate_docfiles,
               output_dir, args.host_name, args.kind_phys,
               args.force_overwrite, _LOGGER)
コード例 #5
0
def _main_func():
    ###############################################################################
    """Parse command line, then parse indicated Fortran files.
    Finally, generate a prototype metadata file for each Fortran file."""
    args = parse_command_line(sys.argv[1:], __doc__)
    verbosity = args.verbose
    if verbosity > 1:
        set_log_level(_LOGGER, logging.DEBUG)
    elif verbosity > 0:
        set_log_level(_LOGGER, logging.INFO)
    # end if
    # Make sure we know where output is going
    output_dir = os.path.abspath(args.output_root)
    # Optional table separator comment
    section_sep = args.section_separator
    if not blank_metadata_line(section_sep):
        emsg = "Illegal section separator, '{}', first character must be # or ;"
        raise CCPPError(emsg.format(section_sep))
    # We need to create a list of input Fortran files
    fort_files = create_file_list(args.files, _FORTRAN_FILENAME_EXTENSIONS,
                                  'Fortran', _LOGGER)
    preproc_defs = args.preproc_directives
    ## A few sanity checks
    ## Make sure output directory is legit
    if os.path.exists(output_dir):
        if not os.path.isdir(output_dir):
            errmsg = "output-root, '{}', is not a directory"
            raise CCPPError(errmsg.format(args.output_root))
        # end if
        if not os.access(output_dir, os.W_OK):
            errmsg = "Cannot write files to output-root ({})"
            raise CCPPError(errmsg.format(args.output_root))
        # end if (output_dir is okay)
    else:
        # Try to create output_dir (let it crash if it fails)
        os.makedirs(output_dir)
    # end if
    # Parse the files and create metadata
    run_env = CCPPFrameworkEnv(_LOGGER,
                               verbose=verbosity,
                               host_files="",
                               scheme_files="",
                               suites="",
                               preproc_directives=preproc_defs)
    _ = parse_fortran_files(fort_files, run_env, output_dir, section_sep,
                            _LOGGER)
コード例 #6
0
    print("{} <source_file> <target_file>".format(cmd))
    print("{} <source_file> [ <source_file> ...] [ <target_directory> ]".format(cmd))
    print("")
    print("Translate the metadata in each <source_file> into a new file")

########################################################################

if __name__ == "__main__":
    # Process the files passed in
    num_args = len(sys.argv)
    if num_args < 3:
        usage(sys.argv[0])
    else:
        ## Init this now so that all Exceptions can be trapped
        logger = init_log('ccpp_capgen')
        set_log_level(logger, logging.INFO)
        ## To cause convert_metadata to stop when an error condition is found
        ## (no metadata file), uncomment out the next line.
        #logger = None
        if os.path.isdir(sys.argv[-1]):
            target_dir = os.path.abspath(sys.argv[-1])
            num_args = num_args - 1
            for index in xrange(1, num_args):
                source_file = os.path.abspath(sys.argv[index])
                filename = os.path.basename(source_file)
                mdfilename = "{}.meta".format('.'.join(filename.split('.')[:-1]))
                dest_file = os.path.join(target_dir, filename)
                dest_mdfile = os.path.join(target_dir, mdfilename)
                convert_file(source_file, dest_file, dest_mdfile, logger)
        else:
            if num_args != 3: