cement.ext.ext_json_configobj

The JSON ConfigObj Extension is a combination of the JsonConfigHandler and ConfigObjConfigHandler which allows the application to read JSON configuration files into a ConfigObj based configuration handler.

Requirements

  • ConfigObj (pip install configobj)

Configuration

This extension does not support any configuration settings.

Usage

myapp.conf

{
    "myapp": {
        "foo": "bar"
    }
}

myapp.py

from cement.core.foundation import CementApp

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

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

    # get config settings
    app.config['myapp']['foo']

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

    # etc...
class cement.ext.ext_json_configobj.JsonConfigObjConfigHandler(*args, **kw)

Bases: cement.ext.ext_configobj.ConfigObjConfigHandler

This class implements the IConfig interface, and provides the same functionality of ConfigObjConfigHandler but with JSON configuration files.

Note This extension has an external dependency on ConfigObj. You must include configobj in your application’s dependencies as Cement explicitly does not include external dependencies for optional extensions.

class Meta

Bases: object

Handler meta-data.

json_module = 'json'

Backend JSON module to use (json, ujson, etc)

label = 'json_configobj'

The string identifier of this handler.

_parse_file(file_path)

Parse JSON configuration file settings from file_path, overwriting existing config settings. If the file does not exist, returns False.

Parameters:file_path – The file system path to the JSON configuration file.
Returns:boolean