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:
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.
- 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.
- 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.
- 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.
- 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.
- 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