esmvaltool/_config.py
def read_config_user_file(config_file, recipe_name):
    """Read config user file and store settings in a dictionary."""
    with open(config_file, 'r') as file:
        cfg = yaml.safe_load(file)

    # set defaults
    defaults = {
        'write_table': True,
        'write_plots': True,
        'write_netcdf': True,
        'compress_netcdf': False,
        'exit_on_warning': False,
        'max_data_filesize': 100,
        'output_file_type': 'ps',
        'table_output_file_type': 'tex',
        'output_dir': './output_dir',
        'save_intermediary_cubes': False,
        'remove_preproc_dir': False,
        'max_parallel_tasks': 1,
        'run_diagnostic': True,
        'profile_diagnostic': False,
        'config_developer_file': None,
        'drs': {},
    }

    for key in defaults:
        if key not in cfg:
            logger.warning(
                "No %s specification in config file, "
                "defaulting to %s", key, defaults[key])
            cfg[key] = defaults[key]

    cfg['output_dir'] = _normalize_path(cfg['output_dir'])
    cfg['config_developer_file'] = _normalize_path(
        cfg['config_developer_file'])

    for key in cfg['rootpath']:
        root = cfg['rootpath'][key]
        if isinstance(root, six.string_types):
            cfg['rootpath'][key] = [_normalize_path(root)]
        else:
            cfg['rootpath'][key] = [_normalize_path(path) for path in root]

    # insert a directory date_time_recipe_usertag in the output paths
    now = datetime.datetime.utcnow().strftime("%Y%m%d_%H%M%S")
    new_subdir = '_'.join((recipe_name, now))
    cfg['output_dir'] = os.path.join(cfg['output_dir'], new_subdir)

    # create subdirectories
    cfg['preproc_dir'] = os.path.join(cfg['output_dir'], 'preproc')
    cfg['work_dir'] = os.path.join(cfg['output_dir'], 'work')
    cfg['plot_dir'] = os.path.join(cfg['output_dir'], 'plots')
    cfg['table_dir'] = os.path.join(cfg['output_dir'], 'tables')
    cfg['run_dir'] = os.path.join(cfg['output_dir'], 'run')

    # Save user configuration in global variable
    for key, value in six.iteritems(cfg):
        CFG_USER[key] = value

    # Read developer configuration file
    cfg_developer = read_config_developer_file(cfg['config_developer_file'])
    for key, value in six.iteritems(cfg_developer):
        CFG[key] = value
    read_cmor_tables(CFG)
    
    return cfg
Read config user file and store settings in a dictionary.
Read config user file and store settings in a dictionary.
Read config user file and store settings in a dictionary .
def read_config_user_file(config_file, recipe_name):
    with open(config_file, 'r') as file:
        cfg = yaml.safe_load(file)
    defaults = {
        'write_table': True,
        'write_plots': True,
        'write_netcdf': True,
        'compress_netcdf': False,
        'exit_on_warning': False,
        'max_data_filesize': 100,
        'output_file_type': 'ps',
        'table_output_file_type': 'tex',
        'output_dir': './output_dir',
        'save_intermediary_cubes': False,
        'remove_preproc_dir': False,
        'max_parallel_tasks': 1,
        'run_diagnostic': True,
        'profile_diagnostic': False,
        'config_developer_file': None,
        'drs': {},
    }
    for key in defaults:
        if key not in cfg:
            logger.warning(
                "No %s specification in config file, "
                "defaulting to %s", key, defaults[key])
            cfg[key] = defaults[key]
    cfg['output_dir'] = _normalize_path(cfg['output_dir'])
    cfg['config_developer_file'] = _normalize_path(
        cfg['config_developer_file'])
    for key in cfg['rootpath']:
        root = cfg['rootpath'][key]
        if isinstance(root, six.string_types):
            cfg['rootpath'][key] = [_normalize_path(root)]
        else:
            cfg['rootpath'][key] = [_normalize_path(path) for path in root]
    now = datetime.datetime.utcnow().strftime("%Y%m%d_%H%M%S")
    new_subdir = '_'.join((recipe_name, now))
    cfg['output_dir'] = os.path.join(cfg['output_dir'], new_subdir)
    cfg['preproc_dir'] = os.path.join(cfg['output_dir'], 'preproc')
    cfg['work_dir'] = os.path.join(cfg['output_dir'], 'work')
    cfg['plot_dir'] = os.path.join(cfg['output_dir'], 'plots')
    cfg['table_dir'] = os.path.join(cfg['output_dir'], 'tables')
    cfg['run_dir'] = os.path.join(cfg['output_dir'], 'run')
    for key, value in six.iteritems(cfg):
        CFG_USER[key] = value
    cfg_developer = read_config_developer_file(cfg['config_developer_file'])
    for key, value in six.iteritems(cfg_developer):
        CFG[key] = value
    read_cmor_tables(CFG)
    return cfg
def read_config_user_file ( config_file , recipe_name ) : with open ( config_file , 'r' ) as file : cfg = yaml . safe_load ( file ) defaults = { 'write_table' : True , 'write_plots' : True , 'write_netcdf' : True , 'compress_netcdf' : False , 'exit_on_warning' : False , 'max_data_filesize' : 100 , 'output_file_type' : 'ps' , 'table_output_file_type' : 'tex' , 'output_dir' : './output_dir' , 'save_intermediary_cubes' : False , 'remove_preproc_dir' : False , 'max_parallel_tasks' : 1 , 'run_diagnostic' : True , 'profile_diagnostic' : False , 'config_developer_file' : None , 'drs' : { } , } for key in defaults : if key not in cfg : logger . warning ( "No %s specification in config file, " "defaulting to %s" , key , defaults [ key ] ) cfg [ key ] = defaults [ key ] cfg [ 'output_dir' ] = _normalize_path ( cfg [ 'output_dir' ] ) cfg [ 'config_developer_file' ] = _normalize_path ( cfg [ 'config_developer_file' ] ) for key in cfg [ 'rootpath' ] : root = cfg [ 'rootpath' ] [ key ] if isinstance ( root , six . string_types ) : cfg [ 'rootpath' ] [ key ] = [ _normalize_path ( root ) ] else : cfg [ 'rootpath' ] [ key ] = [ _normalize_path ( path ) for path in root ] now = datetime . datetime . utcnow ( ) . strftime ( "%Y%m%d_%H%M%S" ) new_subdir = '_' . join ( ( recipe_name , now ) ) cfg [ 'output_dir' ] = os . path . join ( cfg [ 'output_dir' ] , new_subdir ) cfg [ 'preproc_dir' ] = os . path . join ( cfg [ 'output_dir' ] , 'preproc' ) cfg [ 'work_dir' ] = os . path . join ( cfg [ 'output_dir' ] , 'work' ) cfg [ 'plot_dir' ] = os . path . join ( cfg [ 'output_dir' ] , 'plots' ) cfg [ 'table_dir' ] = os . path . join ( cfg [ 'output_dir' ] , 'tables' ) cfg [ 'run_dir' ] = os . path . join ( cfg [ 'output_dir' ] , 'run' ) for key , value in six . iteritems ( cfg ) : CFG_USER [ key ] = value cfg_developer = read_config_developer_file ( cfg [ 'config_developer_file' ] ) for key , value in six . iteritems ( cfg_developer ) : CFG [ key ] = value read_cmor_tables ( CFG ) return cfg
Read config user file and store settings in a dictionary.
Read config user file and store settings in a dictionary .
"""Read config user file and store settings in a dictionary.""" # set defaults # insert a directory date_time_recipe_usertag in the output paths # create subdirectories # Save user configuration in global variable # Read developer configuration file
config_file
recipe_name