maestral.config.user

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

class maestral.config.user.NoDefault[source]

Bases: object

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

Return type

None

save()[source]

Save config into the associated file.

Return type

None

property config_path: str

The ini file where this configuration is stored.

class maestral.config.user.UserConfig(path, defaults=None, load=True, version=<Version('0.0.0')>, backup=False, remove_obsolete=False)[source]

Bases: maestral.config.user.DefaultsConfig

UserConfig class, based on ConfigParser. This class is save 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 (Optional[Dict[str, Dict[str, Any]]]) – 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) –

Return type

None

Note

The get and set arguments number and type differ from the reimplemented methods.

DEFAULT_SECTION_NAME = 'main'
remove_deprecated_options()[source]

Remove options which are present in the file but not in defaults.

Return type

None

backup_path_for_version(version)[source]

Get backup location based on version.

Parameters

version (Optional[packaging.version.Version]) – 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 (Optional[str]) – 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=<class 'maestral.config.user.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