scenario.configdb module

Configuration database management.

CONFIG_DB

Main instance of ConfigDatabase.

class ConfigDatabase

Bases: Logger

Configuration management.

This class loads a list of configuration files, and aggregates all configuration read in a single configuration tree.

See the configuration database documentation.

class FileFormat

Bases: StrEnum

Configuration file formats.

INI = 'INI'

INI configuration file format.

JSON = 'JSON'

JSON configuration file format.

YAML = 'YAML'

YAML configuration file format.

__init__()

Initializes instance attributes and configures logging for the ConfigDatabase class.

_root

Configuration tree.

loadfile(path, format=None, root='')

Loads a configuration file.

Parameters:
  • path – Path of the configuration file to load.

  • format

    File format.

    Determined automatically from the file extension when not specified.

  • root – Root key to load the file from.

savefile(path, format=None, root='')

Saves a configuration file.

Parameters:
  • path – Path of the configuration file to save.

  • format

    File format.

    Determined automatically from the file extension when not specified.

  • root – Root key to save the file from.

set(key, data, origin=None)

Sets a configuration value of any type.

Parameters:
  • key – Configuration key.

  • data

    Configuration data.

    Can be a single value, a dictionary or a list.

    When a os.PathLike is given, it is automatically converted in its string form with os.fspath().

    When None is given, it is equivalent to calling remove() for the given key.

  • origin

    Origin of the configuration data: either a simple string, or the path of the configuration file it was defined in.

    Defaults to code location when not set.

remove(key)

Removes a configuration key (if exists).

Parameters:

key – Configuration key to remove.

show(log_level)

Displays the configuration database with the given log level.

Parameters:

log_levellogging log level.

getkeys()

Returns the list of keys.

Returns:

Configuration keys.

getnode(key)

Retrieves the configuration node for the given key.

Parameters:

key – Searched configuration key.

Returns:

Configuration node when the configuration could be found, or None otherwise.

get(key)
get(key, type)
get(key, type, default)
get(key, type, default)

Returns a configuration value of any type.

Parameters:
  • key – Configuration key.

  • type – Expected value type.

  • default – Default value.

Returns:

Configuration value if set, or default value if set, or None otherwise.