impl#

implementation.

acore_conf.impl.read_config_content(content: str) CommentedConfigParser[source]#

Given the content of a config file, return the loaded config object.

acore_conf.impl.read_config_file(path) CommentedConfigParser[source]#

Given a config file path, return the loaded config object.

acore_conf.impl.update_config_content(content: str, data: Dict[str, Dict[str, str]]) CommentedConfigParser[source]#

Given the content of a config file, load the config object from it, apply changes, and return the config object.

Parameters:
  • content – the string content of the *.conf file.

  • data – python dictionary, the key value pair of the changes. The first key is the section name, the second key is the field name, and the value is the value.

Example, let’s say we want to change the DataDir field in the worldserver section from “.” to “/home/azeroth-server/data”.

# content of the worldserver.conf file
[worldserver]
DataDir = "."
update_config_content(
    content=content,
    data={"worldserver": {"DataDir": "/home/azeroth-server/data"}},
)
acore_conf.impl.update_config_file(path, data: Dict[str, Dict[str, str]]) CommentedConfigParser[source]#

Given a config file path, load the config object from it, apply changes, and return the config object.

It is the same as update_config_content`() but with a file path.

acore_conf.impl.write_config_content(config: CommentedConfigParser) str[source]#

Write the config object to a string.

acore_conf.impl.write_config_file(config: CommentedConfigParser, path) Path[source]#

Write the config object to a file.

acore_conf.impl.apply_changes(path_input, path_output, data: Dict[str, Dict[str, str]]) Path[source]#

Given a config file path, load the config object from it, apply changes, and write to the target file, then return the target file path.

Parameters:
  • path_input – the path of the input *.conf file. Can be str, or pathlib.Path, or pathlib_mate.Path.

  • path_output – the path of the output *.conf file. Can be str, or pathlib.Path, or pathlib_mate.Path. Note that the output file will be overwritten.

  • data – python dictionary, the key value pair of the changes. The first key is the section name, the second key is the field name, and the value is the value.

Returns:

the path of the output file.

See update_config_content() for more details about the update behavior.