ConfigOption Class¶
-
class
AdvConfigMgr.
ConfigOption
(section, name, *args, **kwargs)[source]¶ An individual option in the config
Parameters: - section (ConfigSection) – A pointer to the ConfigSection object that this is a part of
- name (str) – The name of the config object. This is transformed by the optionxform method in the main config manager. by default this is converted to lowercase
- default_value (object) – Default= _UNSET the default value for the item. If set to
_UNSET
this is considered to not have a default. (this allows None to be a valid default setting. - data_type (str) – Default=None: This is the type of data that is stored in the option. this accepts : None, ‘str’, ‘int’, ‘float’, ‘list’, ‘dict’ additional data types can be defined using the DataTypeBase class. If set to None and there is a default value set, this will take the datatype of the default value, otherwise it will be set to ‘str’
- verbose_name (str or None) – Default=None This is the long name for the option (that can show up in the options configuration screen or help screen) This is set to a title case version of the option name with spaces replacing ‘_’
- description (str or None) – Default=None This is the long description for the option, available in the help screens.
- cli_option (str or None) – Default=None This allows the option to be changed via the CLI on startup, this would be a string, tuple or dictionary of options that configure how the cli commands will be handled.
- validations (object) – Default=None: This is a set of validation classes to be run for any options saved.
- keep_if_empty (bool) – Default=True: If set to False the option will be deleted when the value is cleared AND there is no set default value.
- do_not_change (bool) – Default=False If set to True, this will not allow the user to change the option after initial loading.
- do_not_delete (bool) – Default=False If set to True, this will not allow the user to delete the option.
- required_after_load (bool) – Default = False, If set to true, the app should not start without this being set. if there is a CLI_option available, the app should prompt the user for that option, if not, the app should fail with a usefull message.
- autoconvert (bool) – will attempt to autoconvert values to the datatype, this can be disabled if needed. (some types of data may not autoconvert correctly.)
-
from_read
(value, raw=False, validate=True, from_string=False)[source]¶ adds data from a storage module to the system, this ignores the ‘do_not_add’ flag.
Parameters: - value – the value to add
- raw – if set to True will bypass the interpolater
- validate – if False will bypass the validation steps
- from_string – if True will convert from string
Returns: the interpolated value or default value.
-
get
(raw=False, as_string=False)[source]¶ Gets the current value or default interpolated value.
Parameters: raw – if set to True will bypass the interpolater Returns: the interpolated value or default value.
-
set
(value, raw=False, validate=True, force=False)[source]¶ Sets the current value.
Parameters: - value – the value to set
- raw – if set to True will bypass the interpolater
- validate – if False will bypass the validation steps
- force – if True will bypass the lock checks
Returns: the interpolated value or default value.
-
to_write
(raw=False, as_string=False)[source]¶ gets data from the system to save to a storage module,
Parameters: - raw – if set to True will bypass the interpolater
- as_string – returns the value as a strong (passing through the datatype module to_string method)
Returns: the interpolated value or default value.
Returns: the interpolated value or default value.