Pular para conteúdo

Config Manager

get_config_as_dict()

Retorna todas as configurações como um dicionário.

Source code in src\pixcore\config_manager.py
def get_config_as_dict() -> dict:
    """Retorna todas as configurações como um dicionário."""
    config = read_config()
    return {section: dict(config.items(section)) for section in config.sections()}

read_config()

Lê o arquivo de configuração e retorna um objeto ConfigParser.

Source code in src\pixcore\config_manager.py
def read_config() -> configparser.ConfigParser:
    """Lê o arquivo de configuração e retorna um objeto ConfigParser."""
    _ensure_config_exists()
    config = configparser.ConfigParser()
    config.read(CONFIG_FILE)
    return config

set_value(section, key, value)

Define um valor em uma determinada seção do arquivo de configuração.

Source code in src\pixcore\config_manager.py
def set_value(section: str, key: str, value: str):
    """Define um valor em uma determinada seção do arquivo de configuração."""
    config = read_config()
    if not config.has_section(section):
        config.add_section(section)
    config.set(section, key, value)
    write_config(config)

write_config(config)

Escreve o objeto ConfigParser de volta no arquivo.

Source code in src\pixcore\config_manager.py
def write_config(config: configparser.ConfigParser):
    """Escreve o objeto ConfigParser de volta no arquivo."""
    with open(CONFIG_FILE, 'w') as configfile:
        config.write(configfile)