AutoArchive._configuration._core — AutoArchive Developer Manual (ver. 1.0.4)

# AutoArchive._configuration._core

Configuration component internal package.

## Modules

### configuration_component

`ConfigurationComponent` class.

class `AutoArchive._configuration._core.configuration_component.` `ConfigurationComponent`(interfaceAccessor)

  Bases: `AutoArchive._mainf.icomponent.IComponent`

  `IComponent` for support of configuration options and a persistent storage.

  During construction it registers `IAppConfig` and `IStorage` component interfaces to `interfaceAccessor`. It also creates user configuration directory and archive specifications directory if either of them does not exists.

  The `IAppConfig` provides access to configuration options. It is instantiated and populated during construction from `IMainfContext.appEnvironment.options` (command-line options) and from configuration files. The system configuration file is “/etc/aa/aa.conf”. The user configuration file location is determined by values of `Options.USER_CONFIG_FILE` and `Options.USER_CONFIG_DIR` options. The user configuration directory is automatically created if it does not exists. The format of configuration files is defined by the standard `configparser` module (without interpolation).

  The `IAppConfig` instance is populated in a way that same options specified in multiple sources overrides each other so that the order of precedence from highest to lowest is following: command-line, user configuration file, system configuration file. However the implementation recognizes certain types of options that does not follow this rule (see `IConfiguration.__getitem__()`).

  Some of the options, if not specified in neither of possible sources, has some predefined default value. The list of these options with their predefined value follows:

  - `Options.ARCHIVER`: `ArchiverTypes.TarGz`
  - `Options.DEST_DIR`: `os.curdir`
  - `Options.RESTART_AFTER_LEVEL`: 10
  - `Options.ARCHIVE_SPECS_DIR`: `Options.USER_CONFIG_DIR` + “archive_specs”
  - `Options.USER_CONFIG_FILE`: `Options.USER_CONFIG_DIR` + “aa.conf”
  - `Options.USER_CONFIG_DIR`: “~/.config/aa”

  `IStorage` provides access to the persistent storage. It is also instantiated and populated during construction of this class. The storage utilizes local filesystem, specifically a subdirectory of user configuration directory named `storage`. It is automatically created if it does not exists.

  `run`()

    See: `IComponent.run()`.

### _app_config

`_AppConfig` class.

class `AutoArchive._configuration._core._app_config.` `_AppConfig`

  Bases: `AutoArchive._configuration.configuration_base.ConfigurationBase`, `AutoArchive._configuration.iapp_config.IAppConfig`

  Application’s configuration.

  Provides access to application’s configuration. All configuration options that can be accessed via this class are defined as static attributes of `Options`.

  After construction, all options are added and initialized to `None`. It is expected that concrete values will be added using the `_addOrReplaceOption()` method.

  `_addOrReplaceOption`(optionName, value)

    Adds an option and its value replacing the value if already exists.

    String representation of the value is expected. It will be converted to a proper type defined by the option.

    Parameters: | optionName (`str`) – Option that will be added or replaced. value (`str`) – Value of passed option with name `optionName`.
    Raises: | KeyError – If option with name `optionName` does not exists. ValueError – If option’s value is not correct.

  `getArchiveSpecs`()

    See: `IAppConfig.getArchiveSpecs()`.

### _cmdline_arguments_processor

`_CmdlineArgumentsProcessor` class.

class `AutoArchive._configuration._core._cmdline_arguments_processor.` `_CmdlineArgumentsProcessor`(optparseValues)

  Bases: `object`

  Processes command-line arguments and populates `IConfiguration` instance.

  Parameters: | optparseValues (`optparse.Values`) – Command-line options and their values.

  `populateConfiguration`(appConfig)

    Populates `appConfig` with options specified on the command line.

    Note

    Options that are not defined in the `Options` class are skipped; it is assumed that they are commands for command-line UI.

    Parameters: | appConfig (`_AppConfig`) – Configuration that should be populated.

### _config_file_processor

`_ConfigFileProcessor` class.

class `AutoArchive._configuration._core._config_file_processor.` `_ConfigFileProcessor`(appEnvironment, factoryUserConfigDir, factoryUserConfigFileProvider, userConfigDir=None, userConfigFile=None)

  Bases: `object`

  Processes configuration files and populates `IConfiguration` instance.

  Parameters: | appEnvironment (`_AppEnvironment`) – `_AppEnvironment` instance. factoryUserConfigDir (`str`) – Pre-defined path to the user configuration directory. factoryUserConfigFileProvider (`function{str, =>str}`) – Function that returns path to the user configuration file based on the passed configuration directory. userConfigDir (`str`) – Path to the user configuration directory. userConfigFile (`str`) – Path to the user configuration file.

  `populateConfiguration`(configuration)

    Populates `configuration` with options.

    Parameters: | configuration (`_AppConfig`) – Configuration that should be populated.

### _file_storage

`_FileStorage` class.

class `AutoArchive._configuration._core._file_storage.` `_FileStorage`(userConfigDir, quiet)

  Bases: `AutoArchive._configuration.istorage.IStorage`

  Application’s persistent storage.

  Provides access to application’s persistent storage. Any arbitrary variables can be saved to it. Data are stored in text files.

  Storage content is read upon construction and cached into memory. This class does not provide any means to re-read the storage content from disk.

  Parameters: | userConfigDir (`str`) – Path to the user configuration directory.

  `createStoragePortion`(section=None, realm=None)

    See: `IStorage.createStoragePortion()`.

  `getRealms`()

    See: `IStorage.getRealms()`.

  `getValue`(variable, section=None, realm=None)

    See: `IStorage.getValue()`.

  `hasVariable`(variable, section=None, realm=None)

    See: `IStorage.hasVariable()`.

  `removeRealm`(realm)

    See: `IStorage.removeRealm()`.

  `saveValue`(variable, value, section=None, realm=None)

    See: `IStorage.saveValue()`.

  `tryRemoveVariable`(variable, section=None, realm=None)

    See: `IStorage.tryRemoveVariable()`.

### _storage_portion

`_StoragePortion` class.

class `AutoArchive._configuration._core._storage_portion.` `_StoragePortion`(storage, section, realm)

  Bases: `AutoArchive._configuration.istorage_portion.IStoragePortion`

  Portion of the application’s persistent storage.

  See also: `FileStorage`.

  Parameters: | storage (`IStorage`) – `IStorage` which portion shall this instance provide access to. section (`str`) – Section that shall be accessed by default. realm (`str`) – Realm that this portion shall provide access to.

  `getValue`(variable, section=None)

    See: `IStoragePortion.getValue()`.

  `hasVariable`(variable, section=None)

    See: `IStoragePortion.hasVariable()`.

  `saveValue`(variable, value, section=None)

    See: `IStoragePortion.saveValue()`.

  `tryRemoveVariable`(variable, section=None)

    See: `IStoragePortion.tryRemoveVariable()`.

  `realm`

    See: `IStoragePortion.realm`.

  `section`

    See: `IStoragePortion.section`.