# Configuration plugin

Configuration management plugins provide a way to store an application configuration. Openpaperwork_core provides the plugin openpaperwork_core.config that acts a frontend for backend plugins (openpaperowkr_core.config.backend.*). It provides some high level operations (like registering options and their default value). Other plugins and applications should use this frontend only.

When initialized, plugins are expected to register any setting they need. Only the plugin responsible for a setting register it ; Plugins depending on settings registered by one of their dependency do not need to register them.

Backends provide access to the configuration storage (Python’s ConfigParser, Windows registry, Android Content Provider, etc). Reference implementation for backends is openpaperwork_core.config.backend.configparser (based on Python’s ConfigParser).

## Frontend plugin

Paperwork configuration management code

class openpaperwork_core.config.Plugin

  Translate values from the configuration into more usable ones. Provides default values (except for plugins).

  config_add_observer(key: str, callback)
  config_add_plugin(plugin, plugin_list_name=None)
  config_build_simple(section, token, default_value_func)

    Provide a default simple implementation for a new setting that can be registered using ‘config_register’.

    Arguments:

      - section: Section in which option must be stored (see ConfigParser)

      - token: token name for the option (see ConfigParser)

      - default_value_func: function to call to get the default value if none is stored in the file.

  config_get(key: str)
  config_get_default(key: str)
  config_get_plugin_list_name()
  config_get_setting(key: str)
  config_list_options()
  config_list_plugins(plugin_list_name=None)
  config_load()
  config_load_plugins(plugin_list_name, default_plugins=[])
  config_put(key: str, value)

    Store a setting value. Warning: You must call `config_save()` so the changes are actually saved.

    Arguments:

      - key: configuration key,

      - value: can be of many types (str, int, etc).

  config_register(key: str, setting)

    Add another setting to manage. Make this setting available to other components.

    Arguments:

      - key: configuration key

      - setting: Setting must be an object providing a method get() and a method put(value). See `config_build_simple()` to get quickly a default implementation.

  config_remove_observer(key: str, callback)
  config_remove_plugin(plugin, plugin_list_name=None)
  config_reset_plugins(plugin_list_name=None)
  config_save()
  get_deps()
  get_interfaces()
  init(core)

class openpaperwork_core.config.Setting(core, section, token, default_value_func)
  get()
  put(value)

## Backend plugin: File

Manages a configuration file using configparser.

class openpaperwork_core.config.backend.configparser.ConfigBool(value=False)

class openpaperwork_core.config.backend.configparser.ConfigDate(value=datetime.datetime(1971, 1, 1, 0, 0))
  DATE_FORMAT = '%Y-%m-%d'

class openpaperwork_core.config.backend.configparser.ConfigDict(value=None, elements={})
  SEPARATOR_ITEMS = ';'
  SEPARATOR_KEYVALS = '='

class openpaperwork_core.config.backend.configparser.ConfigList(value=None, elements=None)
  SEPARATOR = ';'
  append(value)
  remove(value)

class openpaperwork_core.config.backend.configparser.Plugin
  bug_report_get_attachments(out: dict)
  config_backend_add_observer(section, callback)
  config_backend_add_plugin(opt_name, module_name)
  config_backend_del(section, key)
  config_backend_get(section, key, default=None)
  config_backend_list_active_plugins(opt_name)
  config_backend_load(application_name)
  config_backend_load_plugins(opt_name, default=[])

    Load and init the plugin list from the configuration.

  config_backend_put(section, key, value)

    Section must be a string. Key must be a string.

  config_backend_remove_observer(section, callback)
  config_backend_remove_plugin(opt_name, module_name)
  config_backend_reset_plugins(opt_name)
  config_backend_save(application_name=None)
  get_deps()
  get_interfaces()
  init(core)