yaml_interface#

class confs.yaml_interface.YAML[source]#

DESCRIPTION:

This is the base-class object for YAML-formatted template file updates and the creation of a YAML-formatted file based on the template and the user-specified template variable key and value pairs.

check_yaml(attr_value)[source]#

DESCRIPTION:

This method checks whether the specified value for the attr_value parameter is a YAML-formatted file.

Parameters:
attr_value: str

A Python string containing an attribute value to be check for YAML-formatting.

Returns:
check: bool

A Python boolean valued variable specifying whether the attribute value is a YAML-formatted file.

Return type:

bool

concat_yaml(yaml_file_list, yaml_file_out, fail_nonvalid=True, ignore_missing=False)[source]#

DESCRIPTION:

This method reads a list of YAML-formatted files and concatenates the contents into a single YAML-formatted file.

Parameters:
yaml_file_list: List

A Python list of YAML-formatted files.

yaml_file_out: str

A Python string specifying the path to the YAML-formatted file containing the attributes collected from the respective YAML-formatted file list provided upon entry.

Keywords:
fail_nonvalid: bool, optional

A Python boolean valued variable specifying whether to raise a YAMLInterfaceError exception if a YAML file path for concatenation is not a valid YAML-formatted file.

ignore_missing: bool, optional

A Python boolean valued variable specifying whether to raise a YAMLInterfaceError exception if a YAML file path does not exist.

Raises:
YAMLInterfaceError:
  • raised if a specified file is not a YAML-formatted and/or valid YAML file; invoked only if the respective specified file exists.

  • raised if a specified file path does not exist.

Return type:

None

dict_to_yaml(yaml_dict, default_flow_style=False, indent=4, level=None, nspace=0)[source]#

DESCRIPTION:

This method writes the contents of the Python diction provided upon entry to a YAML-format in accordance with the keyword arguments specified upon entry.

Parameters:
yaml_dict: Dict

A Python dictionary containing the attributes to be written to a YAML-format.

Keywords:
default_flow_style: bool, optional

A Python boolean valued variable; if True upon entry, the contents of the Python dictionary will not be serialized when written to YAML-format; if False upon the entry, the contents of the Python dictionary will be serialized in block style.

indent: int, optional

A Python integer specifying the indent with for nest YAML-formatted blocks.

level: str, optional

A Python string specifying the logger level to accompany the contents of the YAML-formatted Python dictionary; if NoneType upon entry, the contents will be written to standard out; otherwise the specified (and supported) level of the Logger object (see utils/logger_interface.py).

nspace: int, optional

A Python integer specifying the total number of spaces to be used when the Logger object level is used; this is only implemented with the Logger interface is invoked.

Return type:

None

read_concat_yaml(yaml_file, return_obj=False)[source]#

DESCRIPTION:

This method ingests a YAML Ain’t Markup Language (e.g., YAML) formatted file and returns a Python dictionary containing the concatenated attributes of the file; this method is useful for parsing YAML-formatted files with embedded YAML-formatted file directives (e.g., the YAML-formatted file contains paths to external YAML-formatted files to also be parsed).

Parameters:
yaml_file: str

A Python string containing the full-path to the YAML-formatted file to be parsed.

Keywords:
return_obj: bool, optional

A Python boolean valued variable specifying whether to return a Python SimpleNamespace object containing the YAML-formatted file contents; in this instance a Python dictionary will be defined using the contents of the YAML-formatted file and then the Python SimpleNamespace object will be constructed; if True, yaml_obj is returned instead of yaml_dict.

Returns:
Union[Dict, SimpleNamespace] as follows.
yaml_dict: Dict

A Python dictionary containing all attributes ingested from the YAML-formatted file; returned if return_obj is False upon entry.

yaml_obj: SimpleNamespace

A Python SimpleNamespace containing all attributes injested from the YAML-formatted file; returned if return_obj is True upon entry.

Return type:

Union[Dict, SimpleNamespace]

read_yaml(yaml_file, return_obj=False)[source]#

DESCRIPTION:

This method ingests a YAML Ain’t Markup Language (e.g., YAML) formatted file and returns a Python dictionary containing all attributes of the file.

Parameters:
yaml_file: str

A Python string containing the full-path to the YAML file to be parsed.

Keywords:
return_obj: bool, optional

A Python boolean valued variable specifying whether to return a Python SimpleNamespace object containing the YAML-formatted file contents; in this instance a Python dictionary will be defined using the contents of the YAML-formatted file and then the Python SimpleNamespace object will be constructed; if True, yaml_obj is returned instead of yaml_dict.

Returns:
Union[Dict, SimpleNamespace] as follows.
yaml_dict: Dict

A Python dictionary containing all attributes ingested from the YAML-formatted file; returned if return_obj is False upon entry.

yaml_obj: SimpleNamespace

A Python SimpleNamespace object containing all attributes injested from the YAML-formatted file; returned if return_obj is True upon entry.

Return type:

Union[Dict, SimpleNamespace]

write_tmpl(yaml_dict, yaml_path, yaml_template)[source]#

DESCRIPTION:

This method ingests a YAML template file and parses a Python dictionary containing key and value pairs for template variables to be replaced; the updated template is then written to the user-specified path.

Parameters:
yaml_dict: Dict

A Python dictionary containing key and values pairs corresponding to the template variables within the user-specified YAML-formatted template file.

yaml_template: str

A Python string specifying the template variables to seek and update.

yaml_path: str

A Python string specifying the path to the YAML-formatted output file derived from the template.

Return type:

None

write_yaml(yaml_file, in_dict, default_flow_style=False, append=False)[source]#

DESCRIPTION:

This method writes a YAML Ain’t Markup Language (e.g., YAML) formatted file using the specified Python dictionary.

Parameters:
yaml_file: str

A Python string containing the full-path to the YAML file to be written.

in_dict: Dict

A Python dictionary containing the attributes to be written to the YAML file.

Keywords:
default_flow_style: bool, optional

A Python boolean valued variable specifying the output YAML file formatting.

append: bool, optional

A Python boolean valued variable specifying whether to append to an existing YAML-formatted file; if False upon entry any existing YAML-formatted file of the same yaml_file attribute name will be overwritten.

Return type:

None

class confs.yaml_interface.YAMLLoader(stream)[source]#

DESCRIPTION:

This is the base-class object for all YAML file parsing interfaces; it is a sub-class of SafeLoader.

append_constructor(node)[source]#

DESCRIPTION:

This method us the YAML value string append constructor.

Parameters:
node: ScalarNode

A Python ScalarNode variable containing the YAML attribute.

Returns:
string: str

A Python string variable containing the contents of the respective list.

Return type:

str

envvar_constructor(node)[source]#

DESCRIPTION:

This method is the environment variable template constructor.

Parameters:
node: ScalarNode

A Python ScalarNode variable containing the YAML attribute.

Returns:
return: Any

A Python Any type variable containing the expanded/updated YAML attribute(s) using the relevant environment variable(s).

Return type:

Any

include_constructor(node)[source]#

DESCRIPTION:

This method is the file inclusion (i.e., opening and reading) template constructor.

Parameters:
node: ScalarNode

A Python ScalarNode variable containing the YAML attribute.

Returns:
return: Any

A Python Any type variable containing the contents of the YAML-formatted file path.

Return type:

Any