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 with 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, name=settings_manager)

Arguments

  • scope (dict)

Keyword Arguments

  • name (str): name of the variable used for the object instance, default = "settings_manager"

set_bool

def set_bool(self, name, value)

Sets an option by first checking for environment variables, then checking for value already set, then going to the value argument passed. Environment variable values of "1", "true", "y" or "yes" (can be in any case) are considered True. Environment variable values of "0", "false", "n" or "no" (can be in any case) are considered False.

Arguments

  • name (str)
  • value

set_default

def set_default(self, name, value)

Sets the default value for the option if a value is not already set.

Arguments

  • name (str)
  • value

set_from_env

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

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

It is useful to leave the option unset and use default if it already exists in the scope.

Arguments

  • name (str)

Keyword Arguments

  • default: value to be used if there is no environment variable of the same name

set_option

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

Sets an option by first checking for environment variables, then checking for value already set, then going to the value argument passed. Environment variables are always strings that are first coerced to the correct type by checking the type of the value argument. If the value passed is None, then the optional envvar_type argument is checked (If you want to set the option to None, pass the envvar_type as type(None)).

Arguments

  • name (str): name of variable, default = "settings_manager"
  • value: If None is passed a envar_type needs to be given

Keyword Arguments

  • envvar_type

try_include

def try_include(self, filepath)

Tries to include another file into the current scope.

Arguments

  • filepath (str): path to the file trying to be included.