iniconf

The config module manages writing and loading of user preferences

We use ConfigObj Module. With its help, we can read and write ini-files. We are also able to validate it against a specification ini, so there are always correct values after loading.

Use the jukeboxcore.iniconf module for loading the core config file. As a plugin developer, use jukeboxcore.plugins.JB_Plugin.get_config() to obtain the ConfigObj. The ConfigObj behaves like a dictionary. It will have all keys, that you specified in your spec file.

Important

Make sure that every value in your config specification has a valid default value!

For editing a configfile there is the Configer plugin.

jukeboxcore.iniconf.get_section_path(section)[source]

Return a list with keys to access the section from root

Parameters:section (Section) – A Section
Returns:list of strings in the order to access the given section from root
Raises:None
jukeboxcore.iniconf.check_default_values(section, key, validator=None)[source]

Raise an MissingDefaultError if a value in section does not have a default values

Parameters:
  • section (section) – the section of a configspec
  • key (str) – a key of the section
  • validator (Validator) – a Validator object to get the default values
Returns:

None

Raises:

MissingDefaultError

Use this in conjunction with the walk method of a ConfigObj. The ConfigObj should be the configspec! When you want to use a custom validator, try:

configinstance.walk(check_default_values, validator=validatorinstance)
jukeboxcore.iniconf.fix_errors(config, validation)[source]

Replace errors with their default values

Parameters:
  • config (ConfigObj) – a validated ConfigObj to fix
  • validation (ConfigObj) – the resuts of the validation
Returns:

The altered config (does alter it in place though)

Raises:

None

jukeboxcore.iniconf.set_to_default(section, key)[source]

Set the value of the given seciton and key to default

Parameters:
  • section (section) – the section of a configspec
  • key (str) – a key of the section
Returns:

None

Raises:

None

jukeboxcore.iniconf.clean_config(config)[source]

Check if all values have defaults and replace errors with their default value

Parameters:config (ConfigObj) – the configobj to clean
Returns:None
Raises:ConfigError

The object is validated, so we need a spec file. All failed values will be replaced by their default values. If default values are not specified in the spec, a MissingDefaultError will be raised. If the replaced values still fail validation, a ValueError is raised. This can occur if the default is of the wrong type.

If the object does not have a config spec, this function does nothing. You are on your own then.

jukeboxcore.iniconf.load_config(f, spec)[source]

Return the ConfigObj for the specified file

Parameters:
  • f (str) – the config file path
  • spec (str) – the path to the configspec
Returns:

the loaded ConfigObj

Return type:

ConfigObj

Raises:

ConfigError

jukeboxcore.iniconf.get_core_config()[source]

Return the ConfigObj of the main jukebox config file

Returns:the loaded ConfigObj
Return type:ConfigObj
Raises:None