x2gobroker.config module¶
X2GoConfig - helper class for parsing files in INI file format.
-
class
x2gobroker.config.X2GoBrokerConfigFile(config_files=[], defaults={})[source]¶ Bases:
objectClass for processing an INI-file-like configuration file.
If entries are omitted in such a config file, they are filled with default values (as hard-coded in Python X2GoBroker), so the resulting objects always contain the same fields.
The default values are also used to define a data type for each configuration option. An on-the-fly type conversion takes place when loading the configuration file.
-
defaultValues= {'DEFAULT': {'none': 'empty'}}¶
-
get(section, key, key_type=None)¶ Retrieve a value for a given section and key.
- Parameters
section (
str) – the INI file sectionkey (
str) – the INI file key in the given section
- Returns
the value for the given section and key
- Return type
class
-
get_defaults()[source]¶ Get all keys and values from the [DEFAULT] section of the configuration file.
- Returns
the defaults with all keys and values
- Return type
dict
-
get_section(section)[source]¶ Get all keys and values for a certain section of the config file.
- Parameters
section (
str) – the name of the section to get- Returns
the section with all keys and values
- Return type
dict
-
get_type(section, key)[source]¶ Retrieve a value type for a given section and key. The returned value type is based on the default values dictionary.
- Parameters
section (
str) – the INI file sectionkey (
str) – the INI file key in the given section
- Returns
a Python variable type
- Return type
class
-
get_value(section, key, key_type=None)[source]¶ Retrieve a value for a given section and key.
- Parameters
section (
str) – the INI file sectionkey (
str) – the INI file key in the given section
- Returns
the value for the given section and key
- Return type
class
-
has_value(section, key)[source]¶ Test if a given
keyinsectionexists (and has some sort of a value).- Parameters
section (
str) – the INI file sectionkey (
str) – the INI file key in the given section
- Returns
return
Trueif <key> in <section> exists- Return type
bool
-
list_sections()[source]¶ Return a list of all present sections in a config file.
- Returns
list of sections in this config file
- Return type
list
-
property
printable_config_file¶ Returns a printable configuration file as a multi-line string.
-
update_value(section, key, value)[source]¶ Change a value for a given section and key. This method does not have any effect on configuration files.
- Parameters
section (
str) – the INI file sectionkey (
str) – the INI file key in the given sectionvalue (
str,list,bool, …) – the value for the given section and key
-
user_config_file= None¶
-
write()[source]¶ Write the INI file modifications (RawConfigParser object) from RAM to disk.
For writing the first of the
config_filesspecified on instance construction that is writable will be used.
-
write_user_config= False¶
-