maestral.config.user

This module provides user configuration file management and is mostly copied from the config module of the Spyder IDE.

Module Contents

maestral.config.user.logger[source]
maestral.config.user.DefaultsType[source]
maestral.config.user.T[source]
class maestral.config.user.NoDefault[source]
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) –

save(self)[source]

Save config into the associated file.

Return type

None

property config_path(self)[source]

The ini file where this configuration is stored.

Return type

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 and set arguments number and type differ from the reimplemented methods.

DEFAULT_SECTION_NAME = main[source]
remove_deprecated_options(self, 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(self, version)[source]

Get backup location based on version.

Parameters

version (Version | None) – The version of the backup, if any.

Returns

The back for the backup file.

Return type

str

apply_configuration_patches(self, 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(self)[source]

Get the current config version.

Returns

Configuration (not application!) version.

Return type

packaging.version.Version

set_version(self, 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

reset_to_defaults(self, section=None, save=True)[source]

Reset config to default values.

Parameters
  • section (str | None) – The section to reset. If not given, reset all sections.

  • save (bool) – Whether to save the changes to the drive.

Return type

None

get_default(self, section, option)[source]

Get default value for a given section and option.

This is useful for type checking in get method.

Parameters
  • section (str) – Section to search for option.

  • option (str) – Config option.

Returns

Config value or None if section / option do not exist.

Return type

Any

get(self, section, option, default=NoDefault)[source]

Get an option.

Parameters
  • section (str) – Config section to search in.

  • option (str) – Config option to get.

  • default (Any) – Default value to fall back to if not present.

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(self, 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.

Parameters
  • section (str) –

  • option (str) –

  • default_value (Any) –

Return type

None

set(self, 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.

Parameters
  • section (str) – Config section to search in.

  • option (str) – Config option to set.

  • value (Any) – Config value.

  • save (bool) – Whether to save the changes to the drive.

Return type

None

remove_section(self, section, save=True)[source]

Remove section and all options within it.

Parameters
  • section (str) – Section to remove from the config file.

  • save (bool) – Whether to save the changes to the drive.

Returns

Whether the section was removed successfully.

Return type

bool

remove_option(self, section, option, save=True)[source]

Remove option from section.

Parameters
  • section (str) – Section to look for the option.

  • option (str) – Option to remove from the config file.

  • save (bool) – Whether to save the changes to the drive.

Returns

Whether the section was removed successfully.

Return type

bool

cleanup(self)[source]

Remove files associated with config and reset to defaults.

Return type

None

class maestral.config.user.PersistentMutableSet(conf, section, option)[source]

Bases: collections.abc.MutableSet, Generic[T]

Wraps a list in our state file as a MutableSet

Parameters
  • conf (UserConfig) – UserConfig instance to store the set.

  • section (str) – Section name in state file.

  • option (str) – Option name in state file.

add(self, entry)[source]

Add an element.

Parameters

entry (T) –

Return type

None

discard(self, entry)[source]

Remove an element. Do not raise an exception if absent.

Parameters

entry (T) –

Return type

None

update(self, *others)[source]
Parameters

others (T) –

Return type

None

difference_update(self, *others)[source]
Parameters

others (T) –

Return type

None

clear(self)[source]

Clears all elements.

Return type

None