flap.config

Created on Wed Jan 23 21:45:43 2019

Configuration handling for FLAP

@author: Sandor Zoletnik (zoletnik.sandor@ek-cer.hu) Centre for Energy Research

class flap.config.Config

Bases: object

Class containing configuration for FLAP.

Attributes:
config: flap.ConfigParser

The configuration itself.

file_name: str

The configuration filename.

flap.config.get(section, element, datatype=<class 'str'>, default=None, evaluate=False)

Get the value of an element of a specified section from the configuration.

Parameters:
sectionstr

Section of the configuration to get.

elementstr

Element (of section specified) of the configuration to get.

datatypeoptional, default=str

Type to cast configuration value of the element into. Only applied if evaluate is False.

defaultoptional, default=None

Default value to use if section or element does not exist in the configuration.

evaluatebool, optional, default=False

Whether to evaluate the value obtained instead of type casting it.

Returns:
object

The value of the element element of section section in the configuration, type-cast or evaluated.

flap.config.get_all_section(section)

Get all configuration elements from a section of the configuration.

Parameters:
sectionstr

Section of configuration to parse.

Returns:
dict

Dictionary containing the configuration elements and associated values.

flap.config.interpret_config_value(value_str)

Determine the data type from the input string and convert.

Parameters:
value_strstr

The value string to convert.

Conversions: - ‘True’, ‘Yes’ converts to True - ‘False’, ‘No’ converts to False - Starting and ending with ' or " converts to str - If can be converted to int, float or complex, it is converted to the corresponding converted numeric value - Starting and ending with [] converts to list - If all the above fails, keep as str

Returns:
bool | str | int | float | complex | list

Converted value.

flap.config.list_config()

List the contents of the configuration file as stored in memory.

Returns:
None.
flap.config.merge_options(default_options, input_options, data_source=None, section=None)

Merge options dictionaries.

Uses default options of function, input options of function and options read from config file from section section. If exp_id is set, will also look for options in section Module exp_id for options starting with section.

The precedence of options is: default_options < section options < module options < input_options.

Parameters:
default_optionsdict

Default options in a function. This should contain all the possible options.

input_optionsdict

Contents of options argument of function. Option keys can also be abbreviated.

data_sourcedict, optional, default=None

The data source of the measurement. (May be None.)

sectiondict, optional, default=None

Name of the section in the config file related to the function. (May be None.)

Returns:
dict

The merged options dictionary. Abbreviated keys are expanded to full name.

flap.config.read(file_name='flap_defaults.cfg')

Read configuration file.

Parameters:
file_namestr, optional

File name of configuration file, by default ‘flap_defaults.cfg’.

flap.config.test_select_signals()

Test signal selection.