config
Helpers for parsing and writing INI-format config files
dumps(header, properties, **sections)
Serialize a configuration into an INI-formatted string
Parameters:
Name | Type | Description | Default |
---|---|---|---|
header |
str | None
|
A header to render as a comment at the top of the file |
required |
properties |
dict[str, Any]
|
The "main" section contents. Note that this method will add some of its own |
required |
**sections |
dict or list
|
Any additional sections to write. Each section may consist of a set of key-value pairs or they might simply be a list of values |
{}
|
Returns:
Type | Description |
---|---|
str
|
The contents of the configuration, suitable for writing to file |
Source code in enderchest/config.py
get_configurator()
Generate a configuration parser capable of reading or writing INI files
Returns:
Type | Description |
---|---|
ConfigParser
|
The pre-configured configurator |
Source code in enderchest/config.py
list_to_ini(values)
Format a list of values into a string suitable for use in an INI entry
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
list - like
|
the values in the list |
required |
Returns:
Type | Description |
---|---|
str
|
The formatted INI-appropriate value |
Source code in enderchest/config.py
parse_ini_list(entry)
Parse a list from an INI config entry
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry |
str
|
The raw entry from the INI |
required |
Returns:
Type | Description |
---|---|
list of str
|
The parsed entries |
Notes
This method is only for parsing specific values of a key-value entry and not for the whole "section is the key, lines are the values" thing I've got going on.
Source code in enderchest/config.py
read_cfg(config_file)
Read in a configuration file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_file |
Path
|
The path to the configuration file |
required |
Returns:
Type | Description |
---|---|
ConfigParser
|
The parsed configuration |
Raises:
Type | Description |
---|---|
ValueError
|
If the config file at that location cannot be parsed |
FileNotFoundError
|
If there is no config file at the specified location |
Source code in enderchest/config.py
to_ini_key(key)
Style guide enforcement for INI keys
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
The entry key to normalize |
required |
Returns:
Type | Description |
---|---|
str
|
The normalized key |
to_ini_value(value)
Format a value into a string suitable for use in an INI entry
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
Any
|
The value to format |
required |
Returns:
Type | Description |
---|---|
str
|
The formatted INI-appropriate value |