maestral.config.user
¶
This module provides user configuration file management and is mostly copied from the config module of the Spyder IDE.
Module Contents¶
- class maestral.config.user.DefaultsConfig(path)[source]¶
Bases:
configparser.ConfigParser
Class used to save defaults to a file and as base class for UserConfig.
- Parameters:
path (str)
- class maestral.config.user.UserConfig(path, defaults=None, load=True, version=Version('0.0.0'), backup=False, remove_obsolete=False)[source]¶
Bases:
DefaultsConfig
UserConfig class, based on ConfigParser. This class is safe to use from different threads but must not be used from different processes!
- Parameters:
path (str) – Configuration file will be saved to this path.
defaults (_DefaultsType | None) – Dictionary containing options.
version (packaging.version.Version) – Version of the configuration file.
backup (bool) – Whether to create a backup on version changes and on initial setup.
remove_obsolete (bool) – If True, values that were removed from the configuration on version change, are removed from the saved configuration file.
load (bool)
Note
The
get
andset
arguments number and type differ from the reimplemented methods.- remove_deprecated_options(save=True)[source]¶
Remove options which are present in the file but not in defaults.
- Parameters:
save (bool)
- Return type:
None
- backup_path_for_version(version)[source]¶
Get backup location based on version.
- Parameters:
version (packaging.version.Version | None) – The version of the backup, if any.
- Returns:
The back for the backup file.
- Return type:
- apply_configuration_patches(old_version)[source]¶
Apply any patch to configuration values on version changes.
To be reimplemented if patches to configuration values are needed.
- Parameters:
old_version (packaging.version.Version) – Old config version to patch.
- Return type:
None
- get_version()[source]¶
Get the current config version.
- Returns:
Configuration (not application!) version.
- Return type:
packaging.version.Version
- set_version(version, save=True)[source]¶
Set configuration (not application!) version.
- Parameters:
version (packaging.version.Version) – New version to set.
save (bool) – Whether to save changes to drive.
- Return type:
None
- get_default(section, option)[source]¶
Get default value for a given
section
andoption
.This is useful for type checking in get method.
- get(section, option, default=NoDefault)[source]¶
Get an option.
- Parameters:
- Returns:
Config value.
- Raises:
cp.NoSectionError – if the section does not exist.
cp.NoOptionError – if the option does not exist and no default is given.
- Return type:
Any
- set_default(section, option, default_value)[source]¶
Set Default value for a given section, option.
If the section or option does not exist, it will be created.
- set(section, option, value, save=True)[source]¶
Set an
option` on a given ``section
.If section is None, the
option
is added to the default section.
- class maestral.config.user.PersistentMutableSet(conf, section, option)[source]¶
Bases:
MutableSet
[_T
]Wraps a list in our state file as a Mapping
- Parameters:
conf (UserConfig) – UserConfig instance to store the set.
section (str) – Section name in state file.
option (str) – Option name in state file.