maestral.config.user

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

Module Contents

Classes

NoDefault

DefaultsConfig

Class used to save defaults to a file and as base class for UserConfig.

UserConfig

UserConfig class, based on ConfigParser.

maestral.config.user.logger[source]
maestral.config.user.DefaultsType[source]
maestral.config.user.InputDefaultsType[source]
class maestral.config.user.NoDefault[source]
class maestral.config.user.DefaultsConfig(path: str, name: str, suffix: str)[source]

Bases: configparser.ConfigParser

Class used to save defaults to a file and as base class for UserConfig.

save(self)None[source]

Save config into the associated file.

get_config_fpath(self)str[source]

Return the ini file where this configuration is stored.

set_defaults(self, defaults: DefaultsType)None[source]

Set default values and save to defaults folder location.

class maestral.config.user.UserConfig(path: str, name: str, defaults: InputDefaultsType = None, load: bool = True, version: str = '0.0.0', backup: bool = False, remove_obsolete: bool = False, suffix: str = '.ini')[source]

Bases: maestral.config.user.DefaultsConfig

UserConfig class, based on ConfigParser.

Parameters
  • path (str) – Configuration file will be saved to this path.

  • defaults ({} or [(str, {}),]) – Dictionary containing options or list of tuples (sec_name, options)

  • load (bool) – If a previous configuration file is found, load will take the values from this existing file, instead of using default values.

  • version (str) – version of the configuration file in ‘major.minor.micro’ format.

  • backup (bool) – A backup will be created 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.

Notes

The ‘get’ and ‘set’ arguments number and type differ from the reimplemented methods. ‘defaults’ is an attribute and not a method.

DEFAULT_SECTION_NAME = main[source]
get_previous_config_fpath(self)str[source]

Return the last configuration file used if found.

get_config_fpath_from_version(self, version: Optional[str] = None)str[source]

Return the configuration path for given version.

If no version is provided, it returns the current file path.

get_backup_fpath_from_version(self, version: Optional[str] = None, old_version: Optional[str] = None)str[source]

Get backup location based on version.

old_version can be used for checking compatibility whereas version relates to adding the version to the file name.

To be reimplemented if versions changed backup location.

get_defaults_path_name_from_version(self, old_version: Optional[str] = None) → Tuple[str, str][source]

Get defaults location based on version.

To be reimplemented if versions changed defaults location.

get_defaults_fpath_from_version(self, old_version: str = None)str[source]

Get defaults location based on version.

To be reimplemented if versions changed defaults location.

apply_configuration_patches(self, old_version: str = None)None[source]

Apply any patch to configuration values on version changes.

To be reimplemented if patches to configuration values are needed.

get_version(self, version: str = '0.0.0')str[source]

Return configuration (not application!) version.

set_version(self, version: str = '0.0.0', save: bool = True)None[source]

Set configuration (not application!) version.

reset_to_defaults(self, save: bool = True, section: Optional[str] = None)None[source]

Reset config to Default values.

set_as_defaults(self)None[source]

Set defaults from the current config.

get_default(self, section: str, option: str) → Any[source]

Get default value for a given section and option.

This is useful for type checking in get method.

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

Get an option.

Parameters
  • section (str) – Section name. If None is provide use the default section name.

  • option (str) – Option name for section.

  • default – Default value (if not specified, an exception will be raised if option doesn’t exist).

set_default(self, section: str, option: str, default_value: Any)None[source]

Set Default value for a given section, option.

If no defaults exist, no default is created. To be able to set defaults, a call to set_as_defaults is needed to create defaults based on current values.

set(self, section: str, option: str, value: Any, save: bool = True)None[source]

Set an option on a given section.

If section is None, the option is added to the default section.

remove_section(self, section: str)bool[source]

Remove section and all options within it.

remove_option(self, section: str, option: str)bool[source]

Remove option from section.

cleanup(self)None[source]

Remove files associated with config and reset to defaults.