CIME.utils

Common functions used by cime python scripts Warning: you cannot use CIME Classes in this module as it causes circular dependencies

Functions

add_flag_to_cmd

Given a flag and value for a shell command, return a string

add_mail_type_args

analyze_build_log

Capture and report warning count, capture and report errors and undefined references.

batch_jobid

check_name

check for unallowed characters in name, this routine only checks the final name and does not check if path exists or is writable

clear_folder

compute_total_time

Given a map: jobname -> (procs, est-time), return a total time estimate for a given processor pool size

configure_logging

convert_to_babylonian_time

Convert time value to seconds to HH:MM:SS

convert_to_seconds

Convert time value in [[HH:]MM:]SS to seconds

convert_to_string

Convert value back to string.

convert_to_type

Convert value from string to another type.

convert_to_unknown_type

Convert value to it's real type by probing conversions.

copy_globs

Takes a list of globs and copies all files to output_directory.

copy_local_macros_to_dir

Copy any local macros files to the path given by 'destination'.

copy_over_file

Copy a file over a file that already exists

copyifnewer

if dest does not exist or is older than src copy src to dest

deprecate_action

does_file_have_string

Does the text string appear in the filepath file

expect

Similar to assert except doesn't generate an ugly stacktrace.

file_contains_python_function

Checks whether the given file contains a top-level definition of the function 'funcname'

filter_unicode

Sometimes unicode chars can cause problems

find_files

recursively find all files matching a pattern

find_proc_id

Children implies recursive.

find_system_test

Find and import the test matching testname Look through the paths set in config_files.xml variable SYSTEM_TESTS_DIR for components used in this case to find a test matching testname.

fixup_sys_path

format_time

Converts the string input_time from input_format to time_format Valid format specifiers are "%H", "%M", and "%S" % signs must be followed by an H, M, or S and then a separator Separators can be any string without digits or a % sign Each specifier can occur more than once in the input_format, but only the first occurence will be used.

get_all_cime_models

get_batch_script_for_job

get_charge_account

Hierarchy for choosing CHARGE_ACCOUNT: 1.

get_cime_config

get_cime_default_driver

get_cime_root

Return the absolute path to the root of CIME that contains this script

get_config_path

get_current_branch

Return the name of the current branch for a repository

get_current_commit

Return the sha1 of the current HEAD commit

get_current_submodule_status

Return the sha1s of the current currently checked out commit for each submodule, along with the submodule path and the output of git describe for the SHA-1.

get_full_test_name

Given a partial CIME test name, return in form TESTCASE.GRID.COMPSET.MACHINE_COMPILER[.TESTMODS] Use the additional args to fill out the name if needed

get_htmlroot

Get location for test HTML output

get_lids

get_logging_options

Use to pass same logging options as was used for current executable to subprocesses.

get_model

Get the currently configured model value The CIME_MODEL env variable may or may not be set

get_model_config_location_within_cime

get_model_config_root

Get absolute path to model config area"

get_project

Hierarchy for choosing PROJECT: 0.

get_python_libs_location_within_cime

From within CIME, return subdirectory of python libraries

get_schema_path

get_scripts_root

Get absolute path to scripts

get_src_root

Return the absolute path to the root of SRCROOT.

get_template_path

get_time_in_seconds

Convert a time from 'unit' to seconds

get_timestamp

Get a string representing the current UTC time in format: YYYYMMDD_HHMMSS

get_tools_path

get_umask

get_urlroot

Get URL to htmlroot

gunzip_existing_file

gzip_existing_file

Gzips an existing file, removes the unzipped version, returns path to zip file.

id_generator

import_and_run_sub_or_cmd

import_from_file

indent_string

Indents the given string by a given number of spaces

is_comp_standalone

Test if the case is a single component standalone such as FKESSLER

is_last_process_complete

Search the filepath in reverse order looking for expect_text before finding fail_text.

is_python_executable

ls_sorted_by_mtime

return list of path sorted by timestamp oldest first

match_any

Return true if item matches any regex in re_counts' keys.

model_log

new_lid

normalize_case_id

Given a case_id, return it in form TESTCASE.GRID.COMPSET.PLATFORM

parse_args_and_handle_standard_logging_options

Guide to logging in CIME.

parse_test_name

Given a CIME test name TESTCASE[_CASEOPTS].GRID.COMPSET[.MACHINE_COMPILER[.TESTMODS]], return each component of the testname with machine and compiler split.

redirect_logger

redirect_stderr

redirect_stdout

redirect_stdout_stderr

reset_cime_config

Useful to keep unit tests from interfering with each other

resolve_mail_type_args

run_bld_cmd_ensure_logging

run_cmd

Wrapper around subprocess to make it much more convenient to run shell commands

run_cmd_no_fail

Wrapper around subprocess to make it much more convenient to run shell commands.

run_sub_or_cmd

This code will try to import and run each cmd as a subroutine if that fails it will run it as a program in a seperate shell

safe_copy

A flexbile and safe copy routine.

safe_recursive_copy

Copies a set of files from one dir to another.

set_logger_indent

set_model

Set the model to be used in this session

setup_standard_logging_options

start_buffering_output

All stdout, stderr will be buffered after this is called.

stop_buffering_output

All stdout, stderr will not be buffered after this is called.

string_in_list

Case insensitive search for string in list returns the matching list value >>> string_in_list("Brack",["bar", "bracK", "foo"]) 'bracK' >>> string_in_list("foo", ["FFO", "FOO", "foo2", "foo3"]) 'FOO' >>> string_in_list("foo", ["FFO", "foo2", "foo3"])

stringify_bool

symlink_force

Makes a symlink from link_name to target.

touch

transform_vars

Do the variable substitution for any variables that need transforms recursively.

verbatim_success_msg

wait_for_unlocked

Classes

EnvironmentContext

Context manager for environment variables Usage: os.environ['MYVAR'] = 'oldvalue' with EnvironmentContex(MYVAR='myvalue', MYVAR2='myvalue2'): print os.getenv('MYVAR') # Should print myvalue. print os.getenv('MYVAR2') # Should print myvalue2. print os.getenv('MYVAR') # Should print oldvalue. print os.getenv('MYVAR2') # Should print None.

IndentFormatter

SharedArea

Enable 0002 umask within this manager

Timeout

A context manager that implements a timeout.

Exceptions

CIMEError