confu.util

utility functions / classes

Functions


config_parser_dict

def config_parser_dict(config)

Takes a configparser.ConfigParser instance and returns a dict of sections and their keys and values

Arguments

  • config (configparser.ConfigParsers)

Returns

dict


Classes


SettingsManager

SettingsManager(builtins.object)

Scoped settings management with environment variable override support

Methods

__init__

def __init__(self, scope)

Arguments:

  • scope (dict)

set_bool

def set_bool(self, name, value)

Sets and option, first checking for env vars, then checking for value already set, then going to the default value if passed.


set_default

def set_default(self, name, value)

Sets the default value for the option if it's not already set.


set_from_env

def set_from_env(self, name, default=<object object at 0x7fc31f58d5e0>)

Sets a scope variable from a environment variable of the same name.

This is useful to leave the option unset and use default if it already exists in the scope (which may change).


set_option

def set_option(self, name, value, envvar_type=None)

Sets an option, first checking for env vars, then checking for value already set, then going to the default value if passed. Environment variables are always strings, but we try to coerce them to the correct type first by checking the type of the default value provided. If the default value is None, then we check the optional envvar_type arg.