utils.cfg_util module

class utils.cfg_util.CfgParser

Bases: object

parsers = {}
static getConfigParser(cfg_file)

Tries to open the configuration file and return a RawConfigParser. Prints error message and raises exception if config file is not found. A RawConfigParser is created once for each config file for which any CfgParser function is called.

Parameters:cfg_file (str) – The absolute path to the configuration file in *.cfg format.
Returns:A static RawConfigParser instance that is assigned to the specified configuration file.
Return type:RawConfigParser
Raises:ValueError – If no configuration file for cfg_file is found.
static parseOption(cfg_file, section, option, is_optional=False)

Tries to open the config file and parse for the given section and option. Prints error message and raises exception if config file, section or option is not found.

Parameters:
  • cfg_file (str) – The absolute path to the configuration file in *.cfg format.
  • section (str) – The name of the section to parse from the config file.
  • option (str) – The name of the option to parse and return from the section.
  • is_optional (bool, optional) – Is the option to parse optional?
Returns:

The value of the configuration’s option with the specified name in the specified section.

Return type:

str

Raises:

ValueError – If the specified section or option is not found.

static getOptionsDict(cfg_file, section)

Tries to open the config file, parse the given section and return its options as a dictionary. Prints error message and raises exception if config file or section is not found.

Parameters:
  • cfg_file (str) – The absolute path to the configuration file in *.cfg format.
  • section (str) – The name of the section to parse from the config file.
Returns:

A dictionary containing all option-value pairs from the specified configuration section.

Return type:

dict

Raises:

ValueError – If the specified section is not found.

utils.cfg_util.parseQualityConstraintSpecifier(spec)

Reads a quality constraint specifier expression and returns a dictionary containing error metric names or the approx. methods keyword as keys and dictionaries with bound and step values or a list of approx. method IDs as values. The dictionary may also contain an AMOptions key with a dictionary of arbitrary content as value.

Error messages will be logged if there are parsing errors. Each error metric or approximation method will only appear once in the result.

Example specifier expression: BF:bound=4;WC:step=5;AppMethods:PS

Parameters:spec (str) – The quality constraint specifier expression to parse.
Returns:A dictionary containing all information from the specifier string in a format that is easy to access.
Return type:dict