demo_utils.config module

A module makes it easy to set up a configuration directory and read configurations files from that directory.

This module will look for a directory called configuration in the nearby directory structure. It will attempt to first read all files from this directory first, then it will look elsewhere.

See the python docs on ConfigParser for more information on the default config behavior.

This module also supports reading Ambari configurations in the same way that it writes configuration values

Currently it is not possible to write configurations (Python-style configs and Ambari XML).

demo_utils.config.get_conf_dir()

Gets the full path to the configuration directory. Will always end with a forward slash.

Searches through the following list of locations for a directory named ‘configuration’.
  • The current working directory
  • The directory of the python file
  • One level above working directory
  • Two levels above working directory
Returns:path to the configuration directory.
Return type:str
Raises:EnvironmentError – Raised when no configuration directory is found.
demo_utils.config.get_config()

Mimicks the output of the Ambari resource_management library for extracting parameters form XML files.

This function utilizes a configuration directory. After acquiring the path to the directory, the function will find all XML files (that should be formatted Ambari-style). It will then read all parameters and return a dict where every parameter can be accessed.

Parameters:None
Returns:An object which houses the configuration params. Accessed by get_config()[‘configurations’][FILE_NAME][PARAM_NAME]
Return type:dict
demo_utils.config.get_path(config_file)

Returns a fully qualified path for a configuration file. Will check inside configuration directory first.

Parameters:config_file (str) – The path to the configuration file. This can either be a fully qualified path or the path relative to your configuration directory.
Returns:A string containing the full path to the configuration file. If the original
Return type:string
Raises:IOError – Raised when the file can’t be found in either the configuration directory or by the absolute path
demo_utils.config.read_config(config_file)

Read the configuration of a python style configuration file

Parameters:config_file (str) – The path to the configuration file. This can either be a fully qualified path or the path relative to your configuration directory
Returns:Configurations values stored under [SECTION_KEY][PARAMETER_NAME]
Return type:dict
demo_utils.config.read_xml_config(config_file)

Read an Ambari-style XML configuration file

Parameters:config_file (str) – The path to the configuration file. This can either be a fully qualified path or the path relative to your configuration directory.
Returns:A dictionary object where you can access the values via [PARAM_KEY]
Return type:dict