ape.infrastructure.configurationmap.ConfigurationMap

class ape.infrastructure.configurationmap.ConfigurationMap(filename)

A map from configuration files to data

ConfigurationMap constructor

Param:
  • filename: filename(s) to create configuration
__init__(filename)

ConfigurationMap constructor

Param:
  • filename: filename(s) to create configuration

Methods

__init__(filename) ConfigurationMap constructor
get(section, option[, optional, default]) Gets the option from the section as a string
get_boolean(section, option[, optional, default]) Gets a value and casts it to a boolean
get_datetime(section, option[, optional, ...]) Gets a datetime object based on the option (value is timestamp) (see timemap.AbsoluteTime)
get_dictionary(section, option[, optional, ...]) converts a delimiter-separated line to a key:value based dictionary (values are strings)
get_float(section, option[, optional, default]) gets the value as a float
get_int(section, option[, optional, default]) gets the value as an integer
get_list(section, option[, optional, ...]) Gets the value and converts it to a list
get_named_tuple(section, option[, optional, ...]) Converts a line to a named tuple (Like the get_dictionary but keys are properties)
get_ordered_dictionary(section, option[, ...]) converts a delimiter-separated line to a key:value based dictionary (values are strings)
get_relativetime(section, option[, ...]) Gets a relativetime object based on the option (assumes value is timestamp) (see timemap.RelativeTime)
get_tuple(section, option[, optional, ...]) Gets the value and converts it to a list
get_type(cast, section, option[, optional, ...]) Gets a value and casts it
getboolean(section, option[, optional, default]) Gets a value and casts it to a boolean
getfloat(section, option[, optional, default]) gets the value as a float
getint(section, option[, optional, default]) gets the value as an integer
has_option(section, option)
return:True if section has this option
items(section[, optional, default]) Gets tuples of (option, value) pairs for section
log_error(error[, message]) Logs the error in bold red
options(section[, optional, default]) gets a list of option-names
write(path) Writes the current configuration to the path (filename)

Attributes

defaults the [DEFAULT] section
logger
return:A logging object.
parser A SafeConfigParser instance with allow_no_value set to True
sections
return:section names other than DEFAULT
get(section, option, optional=True, default=None)

Gets the option from the section as a string

Param:
  • section: section within the config file
  • option: option within the section
  • optional: If true return default instead of raising error for missing option
  • default: what to return if optional and not found
get_boolean(section, option, optional=False, default=None)

Gets a value and casts it to a boolean

Param:
  • cast: function to cast the value
  • section: section with value
  • option: option in section with value
Returns:

value from section:option

Raise:

ConfigurationError if it can’t be cast

get_datetime(section, option, optional=False, default=None)

Gets a datetime object based on the option (value is timestamp) (see timemap.AbsoluteTime)

Returns:datetime object or default
get_dictionary(section, option, optional=False, default=None, delimiter=', ', separator=':')

converts a delimiter-separated line to a key:value based dictionary (values are strings)

get_float(section, option, optional=False, default=None)

gets the value as a float

get_int(section, option, optional=False, default=None)

gets the value as an integer

Returns:value from section:option
Raise:ConfigurationError if it can’t be cast
get_list(section, option, optional=False, default=None, delimiter=', ')

Gets the value and converts it to a list

Returns:value list with whitespace trimmed
get_named_tuple(section, option, optional=False, default=None, delimiter=', ', separator=':', cast=<type 'str'>)

Converts a line to a named tuple (Like the get_dictionary but keys are properties)

namedtuple(section, fields)

Param:
  • section: section in config (used as name for namedtuple
  • option: with <field><delimiter><value><separator> <field><delimiter><value>
  • optional: if True, missing option returns default
  • default: if optional and no option, return this
  • delimiter: token to separate <field><value> pairs
  • `separator: token to separate each <field><value> pair
  • cast: function to cast all values
get_ordered_dictionary(section, option, optional=False, default=None, delimiter=', ', separator=':')

converts a delimiter-separated line to a key:value based dictionary (values are strings)

get_relativetime(section, option, optional=False, default=None)

Gets a relativetime object based on the option (assumes value is timestamp) (see timemap.RelativeTime)

Returns:RelativeTime object
get_tuple(section, option, optional=False, default=None, delimiter=', ')

Gets the value and converts it to a list

Returns:value list with whitespace trimmed
get_type(cast, section, option, optional=False, default=None)

Gets a value and casts it

Param:
  • cast: function to cast the value
  • section: section with value
  • option: option in section with value
Returns:

value from section:option

Raise:

ConfigurationError if it can’t be cast

getboolean(section, option, optional=False, default=None)

Gets a value and casts it to a boolean

Param:
  • cast: function to cast the value
  • section: section with value
  • option: option in section with value
Returns:

value from section:option

Raise:

ConfigurationError if it can’t be cast

getfloat(section, option, optional=False, default=None)

gets the value as a float

getint(section, option, optional=False, default=None)

gets the value as an integer

Returns:value from section:option
Raise:ConfigurationError if it can’t be cast
has_option(section, option)
Returns:True if section has this option
items(section, optional=False, default=None)

Gets tuples of (option, value) pairs for section

Returns:tuples
log_error(error, message='')

Logs the error in bold red

Param:
  • error: error type (prefix in red and bold)
  • message: descriptive message (red but not bold)
options(section, optional=False, default=None)

gets a list of option-names

Param:
  • section: section-name in the configuration
Returns:

options in section

write(path)

Writes the current configuration to the path (filename)

defaults

the [DEFAULT] section

Returns:dict of default values
logger
Returns:A logging object.
parser

A SafeConfigParser instance with allow_no_value set to True

sections
Returns:section names other than DEFAULT

Navigation