Storages¶
Cfgtree does not make any assumption of the way settings are stored, appart from the fact they are all organized in a hierarchicla structure.
Some common storage format are provided out of the box by cfgtree, but developers can easily implement their own configuration file format.
AnyConfig handled configuration file¶
anyconfig
is a library abstracting the load of a variety of configuration file format (ini,
json, yaml,…)
Single Json file¶
-
class
cfgtree.storages.json.
JsonFileConfigStorage
(environ_var=None, long_param=None, short_param=None, default_filename=None)[source]¶ Settings are stored in a single JSON file
Example:
{ 'version': 1, 'general': { 'verbose': true , 'logfile': 'logfile.log' } }
Usage:
class MyAppConfig(ConfigBaseModel): environ_var_prefix = "MYAPP_" storage = JsonFileConfigStorage( environ_var="MYAPP_COMMON_CONFIG_FILE", long_param="--config", short_param="-c", default_filename="config.json", ) cmd_line_parser = # ... model = { # repeat in model so the arguments in described in --help "configfile": ConfigFileCfg(long_param="--config-file", summary="Config file"), # ... }
-
default_filename
= None¶
-
environ_var
= None¶
-
find_default_filename
(model)¶
-
json_configstorage_default_filename
= None¶ Default filename for the configuration file
Example:
myconfig.json
-
json_configstorage_environ_var
= None¶ Environment variable to set the configuration file name
Example:
DOPPLERR_COMMON_CONFIG_FILE="myconfig.json"
-
json_configstorage_long_param
= None¶ Short parameter to specify the configure file name
Example:
--config-file myconfig.json
-
json_configstorage_short_param
= None¶ Short parameter to specify the configure file name
Example:
-g myconfig.json
-
long_param
= None¶
-
short_param
= None¶
-