ocd.config
– Configuration functionalities¶
Configuration functionalities.
The ConfigUpdater
class handles the following event:
Topic | Event |
---|---|
ocd.config. modification_request | section (string): section to modify |
option (string): option to modify | |
value (string): new value of the option |
The ConfigUpdater.handle_event()
method emits the following event after
updating the configuration:
Topic | Event |
---|---|
ocd.config. modification_replay | success (bool): whether the update is successful or not |
update_msg (string): when updating the configuration, the objects can return a message. The messages are stored here | |
error_msg (string): error message during validation | |
warn_msg (string): warning messages during validation |
If the objects passed to ConfigUpdater
what to update the
their configuration object they must provide a update_config()
. The
return value of these methods, if any, is collated in the update_msg
event
value.
The CONFIG_MOD_REPLY
events are emitted using the ocd_main_loop
ZMQ
server. See ocd.utils.init_zmq_servers()
for more information.
-
ocd.config.
MASTER_CONFIG_FILE
= 'static/ocd.cfg'¶ Name of the master configuration file w.r.t. the ocd package
-
ocd.config.
LOGGER_CONF
= 'static/loggers.cfg'¶ Name of the loggers configuration file w.r.t. the ocd package
-
ocd.config.
CONFIG_MOD_REQUEST
= 'ocd.config.modification_request'¶ Topic of the events emitted to request a configuration request
-
ocd.config.
CONFIG_MOD_REPLY
= 'ocd.config.modification_replay'¶ After the modification has been done send a replay with all the necessary information
-
ocd.config.
config_file_argument
(parser)[source]¶ Add the parser argument to provide and parse the configuration files. The configuration object assigned to the
config
attribute of the parsed namespaceParameters: - parser :
argparse.ArgumentParser
parser to which add the argument
Returns: - parser :
argparse.ArgumentParser
modified parser
- parser :
-
ocd.config.
load_config
(config_file=None, args=None, raise_serious=False, raise_warning=False)[source]¶ Load the configuration file. The default file is loaded and then, if provided, overwritten by the
config_file
.After the configuration files are loaded and if
args
is given, use the latter andoverrides_conf()
to override the configuration entries.Parameters: - config_file : string, optional
name of the configuration file to use to override the configurations
- args :
argparse.Namespace
, optional structure, typically the Namespace create by
argparse
.- raise_serious, raise_warning : bool, optional
options passed to
check_config()
Returns:
-
ocd.config.
move_config
(conf, from_options, from_section, to_section, end_move_date, to_options=None)[source]¶ Move the configuration options from section
from_section
toto_section
warning about every option moved. If an option is not found infrom_section
, it is skipped. If thefrom_section
is not found, skip the move.Parameters: - conf :
pyhetdex.tools.configuration.ConfigParser
configuration to modify
- from_options : list of strings
configuration entries to move
- from_section, to_section : strings
configuration section from and to which the options must be moved.
- end_move_date: string
earliest date at which the automatic moving of the configuration is removed
- to_options : list of strings, optional
if
None
the option names are the same asfrom_options
; otherwise it must be a list with the same length offrom_options
Returns: - conf :
pyhetdex.tools.configuration.ConfigParser
modified configuration
- conf :
-
ocd.config.
check_config
(conf, raise_serious=False, raise_warning=False)[source]¶ Runs check on the configuration and notify the user of possible issues. There are two times of warnings:
ocd.errors.OCDSeriousWarning
: used to notify serious warnings; those warnings are, by default, turned into exceptions;ocd.errors.OCDWarning
: used to notify modifications to the configuration object;
Parameters: - conf :
pyhetdex.tools.configuration.ConfigParser
configuration to modify
- raise_serious : bool, optional
whether to raise
OCDSeriousWarning
- raise_warning : bool, optional
whether to raise
OCDWarning
Returns: - conf :
pyhetdex.tools.configuration.ConfigParser
configuration to modify
Raises: - OCDSeriousWarning
if
raise_serious
isTrue
and there are serious warnings- OCDWarning
if
raise_warning
isTrue
and there are warnings
-
ocd.config.
get_value
(conf, section, option, cast_to=None)[source]¶ Get the value of the configuration option casting it to
cast_to
. Fore empty options (without a=
) returns aNone
Parameters: - conf :
pyhetdex.tools.configuration.ConfigParser
configuration object
- section, option : strings
section and option values
- cast_to : class, optional
class to which cast the value. Allowed values:
None
,int
,float
,bool
Raises: - ocd.errors.OCDValueError
if
cast_to
is not one of the allowed cast classes
- conf :
-
ocd.config.
save_config
(conf)[source]¶ Save the configuration file in a temporary directory.
Parameters: - conf :
pyhetdex.tools.configuration.ConfigParser
configuration to save
Returns: - out_file : string
name of the file
- conf :
-
class
ocd.config.
ConfigUpdater
(conf, *objects)[source]¶ Bases:
object
Update the configuration in all the
objects
.The original configuration object and the list of objects to update are passed when creating one instance.
When an event with topic
CONFIG_MOD_REQUEST
is received, the configuration object is updated and theupdate_config(config)
method of all theobjects
is called. If an object doesn’t have such a method it is skipped.Parameters: - conf :
pyhetdex.tools.configuration.ConfigParser
configuration to modify
- objects :
objects that (might) want to update the configuration
Attributes: - conf, objects :
same as input
- topics : list
list of topics to which the
ConfigUpdater
react
- conf :
-
ocd.config.
config_subcommand
(subparsers)[source]¶ Add a subcommand “config” to handle the configuration file.
Parameters: - subparsers : argparse subparsers object
subparser to use to generate new parsers
Returns: - parser :
argparse.ArgumentParser
modified parser