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]
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)

property config_path: str[source]

The ini file where this configuration is stored.

Return type:

str

save()[source]

Save config into the associated file.

Return type:

None

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(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:

str

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

reset_to_defaults(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(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(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(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(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(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(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()[source]

Remove files associated with config and reset to defaults.

Return type:

None

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.

add(entry)[source]

Add an element.

Parameters:

entry (_T)

Return type:

None

discard(entry)[source]

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

Parameters:

entry (_T)

Return type:

None

update(*others)[source]
Parameters:

others (_T)

Return type:

None

difference_update(*others)[source]
Parameters:

others (_T)

Return type:

None

clear()[source]

Clears all elements.

Return type:

None