pyra.config

Responsible for config related functions.

pyra.config.convert_config(d: dict = _CONFIG_SPEC_DICT, _config_spec: List | None = None) List[source]

Convert a config spec dictionary to a config spec list.

A config spec dictionary is a custom type of dictionary that will be converted into a standard config spec list which can later be used by configobj.

Parameters:
ddict

The dictionary to convert.

_config_specOptional[List]

This should not be set when using this function, but since this function calls itself it needs to pass in the list that is being built in order to return the correct list.

Returns:
list

A list representing a configspec for configobj.

Examples

>>> convert_config(d=_CONFIG_SPEC_DICT)
[...]
pyra.config.create_config(config_file: str, config_spec: dict = _CONFIG_SPEC_DICT) ConfigObj[source]

Create a config file and ConfigObj using a config spec dictionary.

A config spec dictionary is a strictly formatted dictionary that will be converted into a standard config spec list to be later used by configobj.

The created config is validated against a Validator object. This function will remove keys from the user’s config.ini if they no longer exist in the config spec.

Parameters:
config_filestr

Full filename of config file.

config_specdict, default = _CONFIG_SPEC_DICT

Config spec to use.

Returns:
ConfigObj

Dictionary of config keys and values.

Raises:
SystemExit

If config_spec is not valid.

Examples

>>> create_config(config_file='config.ini')
ConfigObj({...})
pyra.config.on_change_tray_toggle() bool[source]

Toggle the tray icon.

This is needed, since tray_icon cannot be imported at the module level without a circular import.

Returns:
bool

True if successful, otherwise False.

See also

pyra.tray_icon.tray_toggle

on_change_tray_toggle is an alias of this function.

Examples

>>> on_change_tray_toggle()
True
pyra.config.save_config(config: ConfigObj | None = CONFIG) bool[source]

Save the config to file.

Saves the ConfigObj to the specified file.

Parameters:
configConfigObj, default = CONFIG

Config to save.

Returns:
bool

True if save successful, otherwise False.

Examples

>>> config_object = create_config(config_file='config.ini')
>>> save_config(config=config_object)
True
pyra.config.validate_config(config: ConfigObj) bool[source]

Validate ConfigObj dictionary.

Ensures that the given ConfigObj is valid.

Parameters:
configConfigObj

Config to validate.

Returns:
bool

True if validation passes, otherwise False.

Examples

>>> config_object = create_config(config_file='config.ini')
>>> validate_config(config=config_object)
True