scistag.common.config_stag.ConfigStag¶
- class ConfigStag[source]¶
Bases:
objectMethods
Returns a single value from the configuration tree, a list or a dictionary of values from the configuration.
Imports all environment variables beginning with environment into the configuration, starting at branch
Loads a configuration file and attaches it to the global configuration tree
Maps a single value from an environment variable to a configuration value (if it was set).
Changes a single value in the configuration tree.
Attributes
__dict____doc____module____weakref__list of weak references to the object (if defined)
Multithreading access lock
The root branch
- classmethod _get_branch(cur_branch, source, may_create=True)[source]¶
Returns the branch for a specific path in the format mainBranch.subBranch.nextBranch.
If may_create is set to true all missing branches in between will be created. If not and the path can not be resolved None will be returned.
- Parameters
- Return type
dict | None
- Returns
The dictionary for the branch
- classmethod get(name, default_value=None)[source]¶
Returns a single value from the configuration tree, a list or a dictionary of values from the configuration.
Note that if you receive an advanced type (such as a list of a dict) you will always receive a copy of the data to prevent accidental modifications via a reference.
- classmethod import_environment(base_branch='', environment='SC_')[source]¶
- Imports all environment variables beginning with environment into the configuration, starting at branch
base_branch.
All underscores in the name will automatically be replaced by dots.
Example: SC_dataBase_connectionString is the environment variables name, our base_branch is “settings” and environment has the value
"SC_"then the content will be stored in settings.dataBase.connectionString.If no parameters are passed automatically all variables beginning with SC_ will be imported into the main branch.
- classmethod load_config_file(source, base_branch='', required=True, environment=None)[source]¶
Loads a configuration file and attaches it to the global configuration tree
- Parameters
source (str) – The file source (accessible via FileStag)
base_branch (str) – The branch name to which this element shall be attached, separated by dots.
required – Defines if an exception shall be raised if this file does not exist
environment (str | None) – If defined environment variables beginning with given shortcut will be imported. UnderScores will be replaced by dots. All variables will be imported relative to base_branch
- classmethod map_environment(environ_name, config_name)[source]¶
Maps a single value from an environment variable to a configuration value (if it was set).
If the environment variable does not exist nothing will be changed.
- Parameters
environ_name – The environment variable name (the source)
config_name – The target name, e.g. azure.connection.credentials.connectionString
- Return type
- Returns
True if the variable was updated
- classmethod set(name, value)[source]¶
Changes a single value in the configuration tree.
Note that if you map an advanced type (such as a list of a dict) you will always receive a copy of the data to prevent accidental modifications via a reference.
- access_lock = <unlocked _thread.RLock object owner=0 count=0>¶
Multithreading access lock
- root_branch = {}¶
The root branch