ait.core.cfg module

AIT Configuration

The ait.core.cfg module provides classes and functions to manage (re)configurable aspects of AIT via a YAML configuration file.

exception ait.core.cfg.AitConfigError

Bases: exceptions.Exception

Raised when a AIT configuration parameter is present, but is in some way incorrect.

exception ait.core.cfg.AitConfigMissing(param)

Bases: exceptions.Exception

Raised when a AIT configuration parameter is missing.

__init__(param)

x.__init__(…) initializes x; see help(type(x)) for signature

class ait.core.cfg.AitConfig(filename=None, data=None, config=None, pathvars=None)

Bases: object

A AitConfig object holds configuration parameters read from a YAML configuration file. The YAML data structure has three levels of parameters, in order: defaults, platform-specific, and host-specific, each taking precedence over the previous one.

NOTE: The platform string is Python’s sys.platform, i.e. ‘linux2’, ‘darwin’, ‘win32’.

__init__(filename=None, data=None, config=None, pathvars=None)

Creates a new AitConfig object with configuration data read from the given YAML configuration file or passed-in via the given config dictionary.

If filename and data are not given, it defaults to the following in order depending on the presence of environment variables:

${AIT_CONFIG}
addPathVariables(pathvars)

Adds path variables to the pathvars map property

get(name, default=None)

Returns the attribute value AitConfig.name or default if name does not exist.

The name may be a series of attributes separated periods. For example, “foo.bar.baz”. In that case, lookups are attempted in the following order until one succeeeds:

  1. AitConfig[‘foo.bar.baz’], and
  2. AitConfig.foo.bar.baz
  3. (If both fail, return default)
getDefaultFilename()
getDefaultPathVariables()
reload(filename=None, data=None)

Reloads the a AIT configuration.

The AIT configuration is automatically loaded when the AIT package is first imported. To replace the configuration, call reload() (defaults to the current config.filename) or reload(new_filename).

ait.core.cfg.expandConfigPaths(config, prefix=None, datetime=None, pathvars=None, parameter_key='', *keys)

Updates all relative configuration paths in dictionary config, which contain a key in keys, by prepending prefix.

If keys is omitted, it defaults to ‘directory’, ‘file’, ‘filename’, ‘path’, ‘pathname’.

See util.expandPath().

ait.core.cfg.flatten(d, *keys)

Flattens the dictionary d by merging keys in order such that later keys take precedence over earlier keys.

ait.core.cfg.loadYAML(filename=None, data=None)

Loads either the given YAML configuration file or YAML data.

Returns None if there was an error reading from the configuration file and logs an error message via ait.core.log.error().

ait.core.cfg.merge(d, o)

Recursively merges keys from o into d and returns d.

ait.core.cfg.replaceVariables(path, datetime=None, pathvars=None)

Return absolute path with path variables replaced as applicable