CIME.XML.namelist_definition.NamelistDefinition

class CIME.XML.namelist_definition.NamelistDefinition(infile, files=None)[source]

Bases: EntryID

Class representing variable definitions for a namelist. This class inherits from EntryID, and supports most inherited methods; however, set_value is unsupported.

Additional public methods: - dict_to_namelist. - is_valid_value - validate

Methods

__init__

Construct a NamelistDefinition from an XML file.

add_attributes

add_child

Add element node to self at root

add_elements_by_group

Add elements from srcobj to self under the appropriate group element, entries to be added must have a child element <file> with value "infile"

attrib

change_file

check_if_comp_var

check_timestamp

Returns True if timestamp matches what is expected

cleanupnode

in env_base.py, not expected to get here

compare_xml

copy

dict_to_namelist

Converts a dictionary of name-value pairs to a Namelist.

get

get_attributes

Return this object's attributes dictionary

get_child

get_child_content

get_children

This is the critical function, its interface and performance are crucial.

get_default_value

Return the default value for the variable named item.

get_description

get_element_text

get_elements_from_child_content

get_entry_nodes

get_group

get_group_name

get_groups

get_id

get_input_pathname

get_node_element_info

get_nodes_by_id

get_optional_child

get_per_stream_entries

get_raw_record

get_resolved_value

A value in the xml file may contain references to other xml variables or to environment variables.

get_type_info

get_valid_value_string

get_valid_values

get_value

Get a value for entry with id attribute vid.

get_value_match

Return the default value for the variable named vid.

get_values

Same functionality as get_value but it returns a list, if the value in xml contains commas the list have multiple elements split on commas

get_version

has

invalidate

is_valid_value

Determine whether a value is valid for the named variable.

lock

A subclass is doing caching, we need to lock the tree structure in order to avoid invalidating cache.

make_child

make_child_comment

name

overwrite_existing_entries

pop

read

Read and parse an xml file into the object.

read_fd

remove_child

rename_group

scan_child

Get an xml element matching nodename with optional attributes.

scan_children

scan_optional_child

Get an xml element matching nodename with optional attributes.

set

set_default_value

set_element_text

set_name

set_node_values

set_nodes

populates the object data types for all nodes that are not part of the skip_groups array returns nodes that do not have attributes of skip_default_entry or per_stream_entry

set_text

set_valid_values

set_value

This function is not implemented.

split_type_string

Split a 'type' attribute string into its component parts.

text

to_string

unlock

validate

Validate a namelist object against this definition.

validate_timestamp

validate_xml_file

validate an XML file against a provided schema file using pylint

write

Write an xml file from data in self

class CacheEntry(tree, root, modtime)[source]

Bases: tuple

count(value, /)[source]

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)[source]

Return first index of value.

Raises ValueError if the value is not present.

modtime[source]

Alias for field number 2

root[source]

Alias for field number 1

tree[source]

Alias for field number 0

add_child(node, root=None, position=None)[source]

Add element node to self at root

add_elements_by_group(srcobj, attributes=None, infile=None)[source]

Add elements from srcobj to self under the appropriate group element, entries to be added must have a child element <file> with value “infile”

check_timestamp()[source]

Returns True if timestamp matches what is expected

cleanupnode(node)[source]

in env_base.py, not expected to get here

dict_to_namelist(dict_, filename=None)[source]

Converts a dictionary of name-value pairs to a Namelist.

The input is assumed to be similar to the output of parse when groupless=True is set. This function uses the namelist definition file to look up the namelist group associated with each variable, and uses this information to create a true Namelist object.

The optional filename argument can be used to assist in error reporting when the namelist comes from a specific, known file.

get_attributes()[source]

Return this object’s attributes dictionary

get_children(name=None, attributes=None, root=None)[source]

This is the critical function, its interface and performance are crucial.

You can specify attributes={key:None} if you want to select children with the key attribute but you don’t care what its value is.

get_default_value(item, attribute=None)[source]

Return the default value for the variable named item.

The return value is a list of strings corresponding to the comma-separated list of entries for the value (length 1 for scalars). If there is no default value in the file, this returns None.

get_resolved_value(raw_value, allow_unresolved_envvars=False, subgroup=None)[source]

A value in the xml file may contain references to other xml variables or to environment variables. These are refered to in the perl style with $name and $ENV{name}.

>>> obj = GenericXML()
>>> os.environ["FOO"] = "BAR"
>>> os.environ["BAZ"] = "BARF"
>>> obj.get_resolved_value("one $ENV{FOO} two $ENV{BAZ} three")
'one BAR two BARF three'
>>> obj.get_resolved_value("2 + 3 - 1")
'4'
>>> obj.get_resolved_value("0001-01-01")
'0001-01-01'
>>> obj.get_resolved_value("$SHELL{echo hi}") == 'hi'
True
get_value(vid, attribute=None, resolved=True, subgroup=None)[source]

Get a value for entry with id attribute vid. or from the values field if the attribute argument is provided and matches

get_value_match(vid, attributes=None, exact_match=True, entry_node=None)[source]

Return the default value for the variable named vid.

The return value is a list of strings corresponding to the comma-separated list of entries for the value (length 1 for scalars). If there is no default value in the file, this returns None.

get_values(vid, attribute=None, resolved=True, subgroup=None)[source]

Same functionality as get_value but it returns a list, if the value in xml contains commas the list have multiple elements split on commas

is_valid_value(name, value)[source]

Determine whether a value is valid for the named variable.

The value argument must be a list of strings formatted as they would appear in the namelist (even for scalar variables, in which case the length of the list is always 1).

lock()[source]

A subclass is doing caching, we need to lock the tree structure in order to avoid invalidating cache.

read(infile, schema=None)[source]

Read and parse an xml file into the object. The schema variable can either be a path to an xsd schema file or a dictionary of paths to files by version.

scan_child(nodename, attributes=None, root=None)[source]

Get an xml element matching nodename with optional attributes.

Error unless exactly one match.

scan_optional_child(nodename, attributes=None, root=None)[source]

Get an xml element matching nodename with optional attributes.

Return None if no match.

set_nodes(skip_groups=None)[source]

populates the object data types for all nodes that are not part of the skip_groups array returns nodes that do not have attributes of skip_default_entry or per_stream_entry

set_value(vid, value, subgroup=None, ignore_type=True)[source]

This function is not implemented.

split_type_string(name)[source]

Split a ‘type’ attribute string into its component parts.

The name argument is the variable name. This is used for error reporting purposes.

The return value is a tuple consisting of the type itself, a length (which is an integer for character variables, otherwise None), and the size of the array (which is 1 for scalar variables).

validate(namelist, filename=None)[source]

Validate a namelist object against this definition.

The optional filename argument can be used to assist in error reporting when the namelist comes from a specific, known file.

validate_xml_file(filename, schema)[source]

validate an XML file against a provided schema file using pylint

write(outfile=None, force_write=False)[source]

Write an xml file from data in self