cement.ext.ext_configobj

The ConfigObj Extension provides configuration handling based on configobj. It is a drop-in replacement for the default config handler cement.ext.ext_configparser.ConfigParserConfigHandler.

One of the primary features of ConfigObj is that you can access the application configuration as a dictionary object.

Requirements

  • ConfigObj (pip install configobj)

Configuration

This extension does not honor any application configuration settings.

Usage

from cement.core.foundation import CementApp

class MyApp(CementApp):
    class Meta:
        label = 'myapp'
        extensions = ['configobj']
        config_handler = 'configobj'

with MyApp() as app:
    app.run()

    # get a config setting
    app.config['myapp']['foo']

    # set a config setting
    app.config['myapp']['foo'] = 'bar2'

    # etc.
class cement.ext.ext_configobj.ConfigObjConfigHandler(*args, **kw)

Bases: cement.core.config.CementConfigHandler, ConfigObj

This class implements the IConfig interface, and sub-classes from configobj.ConfigObj, which is an external library and not included with Python. Please reference the ConfigObj documentation for full usage of the class.

Arguments and keyword arguments are passed directly to ConfigObj on initialization.

class Meta

Bases: object

Handler meta-data.

interface

alias of IConfig

ConfigObjConfigHandler._parse_file(file_path)

Parse a configuration file at file_path and store it.

Parameters:file_path – The file system path to the configuration file.
Returns:boolean (True if file was read properly, False otherwise)
ConfigObjConfigHandler.add_section(section)

Add a section to the configuration.

Parameters:section – The configuration [section] to add.
ConfigObjConfigHandler.get(section, key)

Get a value for a given key under section.

Parameters:
  • section – The configuration [section].
  • key – The configuration key under the section.
Returns:

unknown (the value of the key)

ConfigObjConfigHandler.get_section_dict(section)

Return a dict representation of a section.

Parameters:section – The section of the configuration. I.e. [block_section]
Returns:dict
ConfigObjConfigHandler.get_sections()

Return a list of [section] that exist in the configuration.

Returns:list
ConfigObjConfigHandler.has_section(section)

Return True/False whether the configuration [section] exists.

Parameters:section – The section to check for.
Returns:bool
ConfigObjConfigHandler.keys(section)

Return a list of keys for a given section.

Parameters:section – The configuration [section].
ConfigObjConfigHandler.merge(dict_obj, override=True)

Merge a dictionary into our config. If override is True then existing config values are overridden by those passed in.

Parameters:
  • dict_obj – A dictionary of configuration keys/values to merge into our existing config (self).
  • override – Whether or not to override existing values in the config.
Returns:

None

ConfigObjConfigHandler.set(section, key, value)

Set a configuration key value under [section].

Parameters:
  • section – The configuration [section].
  • key – The configuration key under the section.
  • value – The value to set the key to.
Returns:

None