cowbird.constants
Constant settings for Cowbird application.
Constants defined with format COWBIRD_[VARIABLE_NAME] can be matched with corresponding
settings formatted as cowbird.[variable_name] in the cowbird.ini configuration file.
Note
Since the cowbird.ini file has to be loaded by the application to retrieve various configuration settings,
constant COWBIRD_INI_FILE_PATH (or any other path variable defined before it - see below) has to be defined
by environment variable if the default location is not desired (ie: if you want to provide your own configuration).
Attributes
Functions
|
Get logging level from INI configuration file or fallback to default |
|
Find the equivalent setting name of the provided environment variable name. |
|
Search in order for matched value of |
|
Validates that some value is provided for every mandatory configuration setting. |
Module Contents
- cowbird.constants._get_default_log_level() AnyLogLevel[source]
Get logging level from INI configuration file or fallback to default
INFOif it cannot be retrieved.
- cowbird.constants.COWBIRD_CONSTANTS = ['COWBIRD_CONSTANTS', 'COWBIRD_MODULE_DIR', 'COWBIRD_ROOT', 'COWBIRD_ADMIN_PERMISSION'][source]
- cowbird.constants.get_constant_setting_name(name: str) str[source]
Find the equivalent setting name of the provided environment variable name.
Lower-case name and replace all non-ascii chars by _. Then, convert known prefixes with their dotted name.
- cowbird.constants.get_constant(constant_name: str, settings_container: cowbird.typedefs.AnySettingsContainer | None = None, settings_name: str | None = None, default_value: cowbird.typedefs.SettingValue | None = None, raise_missing: bool = True, print_missing: bool = False, raise_not_set: bool = True) cowbird.typedefs.SettingValue[source]
- Search in order for matched value of
constant_name: search in
COWBIRD_CONSTANTSsearch in settings if specified
search alternative setting names (see below)
search in
cowbird.constantsdefinitionssearch in environment variables
Parameter
constant_nameis expected to have the formatCOWBIRD_[VARIABLE_NAME]although any value can be passed to retrieve generic settings from all above-mentioned search locations.If
settings_nameis provided as alternative name, it is used as is to search for results ifconstant_namewas not found. Otherwise,cowbird.[variable_name]is used for additional search when the formatCOWBIRD_[VARIABLE_NAME]was used forconstant_name(i.e.:COWBIRD_ADMIN_USERwill also search forcowbird.admin_userand so on for corresponding constants).- Parameters:
constant_name – key to search for a value
settings_container – WSGI application settings container (if not provided, uses found one in current thread)
settings_name – alternative name for settings if specified
default_value – default value to be returned if not found anywhere, and exception raises are disabled.
raise_missing – raise exception if key is not found anywhere
print_missing – print message if key is not found anywhere, return
Noneraise_not_set – raise an exception if the found key is
None, search until last case if others areNone
- Returns:
found value or default_value
- Raises:
ValueError – if resulting value is invalid based on options (by default raise missing/
Nonevalue)LookupError – if no appropriate value could be found from all search locations (according to options)
- Search in order for matched value of