b3j0f.conf.configurable.core module

class b3j0f.conf.configurable.core.MetaConfigurable[source]

Bases: type

Meta class for Configurable.

class b3j0f.conf.configurable.core.Configurable(unified_category=None, to_configure=None, conf_paths=None, drivers='b3j0f.conf.driver.file._json.JSONConfDriver, b3j0f.conf.driver.file._ini.INIConfDriver', auto_conf=True, reconf_once=False, log_lvl='INFO', log_name=None, log_path='.', log_info_format='[%(asctime)s] [%(levelname)s] [%(name)s] %(message)s', log_debug_format='[%(asctime)s] [%(levelname)s] [%(name)s] [%(process)d] [%(thread)d] [%(pathname)s] [%(lineno)d] %(message)s', log_warning_format='[%(asctime)s] [%(levelname)s] [%(name)s] %(message)s', log_error_format='[%(asctime)s] [%(levelname)s] [%(name)s] %(message)s', log_critical_format='[%(asctime)s] [%(levelname)s] [%(name)s] %(message)s')[source]

Bases: object

Manages class conf synchronisation with conf resources.

AUTO_CONF = 'auto_conf'
CONF = 'CONFIGURATION'
CONF_PATH = 'configuration/configurable.conf'
CONF_PATHS = 'conf_paths'
CRITICAL_FORMAT = '[%(asctime)s] [%(levelname)s] [%(name)s] %(message)s'
DEBUG_FORMAT = '[%(asctime)s] [%(levelname)s] [%(name)s] [%(process)d] [%(thread)d] [%(pathname)s] [%(lineno)d] %(message)s'
DEFAULT_DRIVERS = 'b3j0f.conf.driver.file._json.JSONConfDriver,b3j0f.conf.driver.file._ini.INIConfDriver'
DRIVERS = 'drivers'
ERROR_FORMAT = '[%(asctime)s] [%(levelname)s] [%(name)s] %(message)s'
INFO_FORMAT = '[%(asctime)s] [%(levelname)s] [%(name)s] %(message)s'
INIT_CAT = 'init_cat'

initialization category

LOG = 'LOG'
LOG_CRITICAL_FORMAT = 'log_critical_format'

crit log format property

LOG_DEBUG_FORMAT = 'log_debug_format'

debug log format property name

LOG_ERROR_FORMAT = 'log_error_format'

error log format property name

LOG_INFO_FORMAT = 'log_info_format'

info log format property name

LOG_LVL = 'log_lvl'

logging level property name

LOG_NAME = 'log_name'

logger name property name

LOG_PATH = 'log_path'

logging path property name

LOG_WARNING_FORMAT = 'log_warning_format'

warn log format property name

RECONF_ONCE = 'reconf_once'
WARNING_FORMAT = '[%(asctime)s] [%(levelname)s] [%(name)s] %(message)s'
apply_configuration(conf=None, conf_paths=None, drivers=None, logger=None, override=True, to_configure=None)[source]

Apply conf on a destination in 5 phases:

  1. identify the right driver to use with conf_paths to parse.

  2. for all conf_paths, get conf which match

    with input conf.

  3. apply parsing rules on conf_path params.

  4. put values and parsing errors in two different dictionaries.

  5. returns both dictionaries of param values and errors.

Parameters:
  • conf (Configuration) – conf from where get conf
  • conf_paths (list of str) – conf files to parse. If conf_paths is a str, it is automatically putted into a list
  • override (bool) – if True (by default), override self configuration
  • to_configure – object to configure. self by default.
auto_conf
conf

Get conf with parsers and self property values

conf_paths

Get all type conf files and user files.

Returns:self conf files
Return type:tuple
configure(conf, logger=None, to_configure=None)[source]

Update self properties with input params only if: - self.configure is True - self.auto_conf is True - param conf ‘configure’ is True - param conf ‘auto_conf’ is True

This method may not be overriden. see _configure instead

Parameters:
  • conf (Configuration) – object from where get paramters
  • to_configure – object to configure. self if equals None.
drivers
get_conf(conf=None, conf_paths=None, drivers=None, logger=None, override=True)[source]

Get a dictionary of params by name from conf, conf_paths and drivers

Parameters:
  • conf (Configuration) – conf to update. If None, use self.conf
  • conf_paths (list of str) – list of conf files. If None, use self.conf_paths
  • logger (Logger) – logger to use for logging info/error messages. If None, use self.logger
  • drivers (list) – ConfDriver to use. If None, use self drivers.
  • override (bool) – if True (by default), override self configuration
  • to_configure – object to configure. self by default.
log_critical_format
log_debug_format
log_error_format
log_info_format
log_lvl

Get this logger lvl.

Returns:self logger lvl
Return type:str
log_name
log_path
log_warning_format
logger
newLogger()[source]

Get a new logger related to self properties.

reconf_once
restart(criticals, to_configure=None)[source]

Restart a configurable object with critical parameters.

Parameters:
  • to_configure – object to configure with critical parameters
  • criticals (tuple) – list of critical parameters
set_conf(conf_path, conf, driver=None, logger=None)[source]

Set params on input conf_path.

Parameters:
  • conf_paths (str) – conf_path to udate with params
  • parameter_by_categories (dict) – (dict(str: dict(str: object))
  • logger (Logger) – logger to use to set params.
exception b3j0f.conf.configurable.core.ConfigurableError[source]

Bases: exceptions.Exception

Handle Configurable errors