ConfigManager Class

class AdvConfigMgr.ConfigManager(version=None, migrations=None, storage_config=None, storage_managers=None, default_storage_managers=None)[source]
Parameters:
  • allow_no_value – allow empty values.
  • empty_lines_in_values
  • allow_add_from_storage – allow adding sections and options directly from the storage
  • allow_create_on_set – allows sections to be created when the set command is used. the set command can only be used to set the values of options, so this REQUIRES using dot-notation.
  • no_sections – this will disable all sections and all options will be accessible from the base manager object. (this creates a section named “default_section”.) .. warning:: converting from simple configurations to sections may require manual data minipulation!
  • section_defaults – a dictionary of settings used as defaults for all sections created
  • interpolation – can be defined if interpolation is requested or required.
  • section_option_sep (str) – defines a seperator character to use for getting options using the dot_notation style of query. defaults to ‘.’, in which case options can be queried by calling ConfigManager[section.option] in addition to ConfigManager[section][option]. If this is set to None, dot notation will be disabled.
  • cli_program – the name of the program for the cli help screen (by default this will use the program run to launch the app)
  • cli_desc – the text to show above the arguments in the cli help screen.
  • cli_epilog – the text to show at the end of the arguments in the cli help screen.
  • raise_error_on_locked_edit – if True, will raise an error if an attempt to change locked options, if False (default) the error is suppressed and the option will not be changed.
  • storage_managers (BaseStorageManager) – a list of storage managers to use, if none are passed, the configuration will not be able to be saved.
  • cli_parser_name – the name of the cli parser if not the default. set to None if the CLI parser is not to be used.
  • cli_group_by_section – True if cli arguments shoudl be grouped by section for help screens.
  • version_class (Version or str or None) – ‘loose’, ‘strict’, a subclass of the Version class or None for no versioning.
  • version (str) – the version number string.
  • version_option_name (str) – the option named used to store the version for each section, {section} will be replaced by the name of the section.
  • version_allow_unversioned (bool) – if True, the system will import unversioned data, if false, the version of the data must be specified when importing any data.
  • version_enforce_versioning (bool) – if True, the system will raise an error if no version is set at the section or base level.
  • version_disable_cross_section_copy (bool) – if True, cross section copy will not work. Used when you have plugins from different authors and you want to segment them.
  • version_make_migrations (list) – this is a list of migrations that can be performed, (see migration)
  • kwargs – if “no_sections” is set, all section options can be passed to the ConfigManager object.
  • data_dict (ConfigDict) – any dictionary that can support the number of levels needed.
  • version – the sering version number.
  • migrations (list) – a list of migration dictionaries.
  • storage_config (dict) – a dictionary of storage configuration dictionaries. These would be in the format of {‘storage_name’:{<config_dict>},’storage_name’:{<config_dict>}}. See specific storage managers for details of the config dict entries.
  • storage_managers – a list or set of storage managers to use, if not passed, the file storage manager is used.
  • default_storage_managers (list) – a list or string indicating the default storage manager(s) names to use if no names are passed during read/write operations. if None (the default) all conifgured storage managers are polled.
add(*args, **kwargs)[source]

Adds configuration options:

add('section1', 'section2', 'section3')
add(section_def_dict1, section_def_dict2, section_def_dict3)
add([list of section_def_dicts])
add('section_name.option_name', 'section_name.option_name')

add(section_name1='option_name1', section_name2='option_name2')
add(section_name=section_def_dict, section_name2=section_def_dict)
add(section_name=[list_of_option_names or dicts], section_name=(list of option names or dicts]

section_def_dict keys

Key Default Description
‘name’ None The name of the section
‘verbose_name’ None The verbose name of the section
‘description’ None A long description of the section
‘storage’ None The name of the storage location (if used)
‘keep_if_empty’ False Keep the section even if all options ahve been deleted
‘store_default’ False Store defaults in storage medium
‘locked’ False If True, do not allow any changes to the section
‘allow_create_on_load’ True Allow new options to be created directly from the storage medium for example, if you hand edit the ini file and add new options
‘option_defaults’ None Allows a dict to be passed with defaults for any new options in this section this will replace any system wide option defaults specified.
‘options’ None Provides a list of options to be added to the section,

Note

When no sections are used, this will redirect to ConfigSection.add()

add_section(section, force_add_default=False, **kwargs)[source]

Create a new section in the configuration.

Raise DuplicateSectionError if a section by the specified name already exists.

read(sections=None, storage_names=None, override_tags=False, data=None, **kwargs)[source]

runs the read from storage process for the selected or configured managers

Parameters:
  • storage_names – If None, will read from all starnard storage managers, if a string or list, will read from the selected ones following the configured tag settings.
  • sections – If None, will read from all sections, if string or list, will read from the selected ones following the configured tag settings.
  • override_tags – if True, this will override the configured storage tag settings allowing things like exporting the full config etc.
  • data – if a single storage tag is passed, then data can be passed to that storage manager for saving. this will raise an AssignmentError if data is not None and more than one storage tag is passed.
write(sections=None, storage_names=None, override_tags=False, **kwargs)[source]

runs the write to storage process for the selected or configured managers

Parameters:
  • storage_names – If None, will write to all starnard storage managers, if a string or list, will write to the selected ones following the configured tag settings.
  • sections – If None, will write to all sections, if string or list, will write to the selected ones following the configured tag settings.
  • override_tags – if True, this will override the configured storage tag settings allowing things like exporting the full config etc.
Returns:

if ONLY one storage_tag is passed, this will return the data from that manager if present.