gs.config API Reference

The package exports the following API symbols.

Configuration

class gs.config.Config(configset, configpath=None)[source]

The configuration.

Method:

Config(configset, configpath=None)

Parameters:
  • configset (str) – The name of the configuration set to read.
  • configpath (str) – The path to the configration file. If None and Zope is being used then etc/gsconfig.ini is read from instance directory.
Raises:

The actual parsing of the configuration file is done by the ConfigParser module.

get(configtype, strict=True)[source]

Get the values defined in a section

Parameters:
  • configtype (str) – The ID for the section to retrieve.
  • strict (bool) – If True (the default) then a ConfigNoOption error is raised when an option is present in the configuration file but absent from the schema. When False the option is ignored.
Returns:

The values for all options in the provided section.

Return type:

A dict containing optionId: value pairs. The values are coerced using the schema set by set_schema().

Raises:
  • ConfigNoSectionError – No section for the ID in configtype exists.
  • ConfigNoOption – An option was present in the configuration file but absent from the section.
  • ConfigConvertError – An option could not be coerced.

Example:

smtpConfig = config.get('smtp')
get_schema(configtype)[source]

Get the schema that is currently set for a section.

Parameters:confgitype (str) – The identifier for the section.
Returns:The schema that is currently set for the section.
Return type:A dict, containing optionId: type pairs.
Raises:ConfigNoSchemaError – No schema with the identifer configtype found.
keys()[source]

Get the list of sections that are currently defined.

Returns:A list of sections for the configuration set.
Return type:list
set_schema(configtype, schema)[source]

Set the schema that is used for parsing the options.

Parameters:
  • configtype (str) – The identifier for the section of the configration.
  • schema (dict) – The schema for the section, as optionId: type pars.

When the value for an option in a section is retrieved its type is coerced from a string to one of the types passed in as :param:`schema`.

Example:

s = {'station': str,
     'frequency': int,}
conf.set_schema('radio', s)
gs.config.getInstanceId()[source]

Get the ID of the current instance.

Returns:The ID the of the instance, or default
Return type:str

It can be useful to have multiple instances running on one server, but configured seperately. The getInstanceId function gets the ID of the current instance by looking it up in the HTTP_INSTANCEID property of the current Zope HTTP request. If Zope (and HTTP) are not being used then default is returned.

This function is defined in gs.config mostly out of convinience, as GroupServer normally organises its configuration into instances.

Errors

The possible configuration errors.

exception gs.config.errors.ConfigConvertError[source]

An error raissed when the value cannot be converted.

exception gs.config.errors.ConfigError[source]

A generic error with the configuration.

exception gs.config.errors.ConfigFileError[source]

An error with reading the config file

exception gs.config.errors.ConfigNoOptionError[source]

An error raised when an option is not defined in a schema

exception gs.config.errors.ConfigNoSchemaError[source]

An error raised when there is no schema

exception gs.config.errors.ConfigNoSectionError[source]

An error raised when there is no configuration section specified.

exception gs.config.errors.ConfigPathError[source]

An error with the path to the config file.

exception gs.config.errors.ConfigSetError[source]

An error with the structure of the config file.