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 namespace

Parameters:
parser : argparse.ArgumentParser

parser to which add the argument

Returns:
parser : argparse.ArgumentParser

modified 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 and overrides_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:
config : pyhetdex.tools.configuration.ConfigParser
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 to to_section warning about every option moved. If an option is not found in from_section, it is skipped. If the from_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 as from_options; otherwise it must be a list with the same length of from_options

Returns:
conf : pyhetdex.tools.configuration.ConfigParser

modified configuration

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:

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 is True and there are serious warnings

OCDWarning

if raise_warning is True 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 a None

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

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

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 the update_config(config) method of all the objects 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

handle_event(self, tcs_topic, tcs_event)[source]

When an event with the given topic arrives, decide whether it’s time to run a shot.

Parameters:
tcs_topic : string

topic of the event

tcs_event : dict

event to handle

Returns:
bool

whether the event triggers some computation

_update_config(self, tcs_event)[source]

Update the configuration file using the tcs_event.

Get the section, option and value to update from the event and then update the configuration.

Parameters:
tcs_event : dict

event to handle

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

ocd.config._copy_conf(args)[source]

Copy the configuration files into the target directory

Parameters:
args : Namespace

parsed command line arguments

ocd.config._send_conf(args)[source]

Copy the configuration files into the target directory

Parameters:
args : Namespace

parsed command line arguments