ahriman.core.configuration package

Submodules

ahriman.core.configuration.configuration module

class Configuration(allow_no_value: bool = False)

Bases: RawConfigParser

extension for built-in configuration parser

ARCHITECTURE_SPECIFIC_SECTIONS

(class attribute) known sections which can be architecture specific. Required by dump and merging functions

Type:

list[str]

SYSTEM_CONFIGURATION_PATH

(class attribute) default system configuration path distributed by package

Type:

Path

includes

list of includes which were read

Type:

list[Path]

path

path to root configuration file

Type:

Path | None

repository_id

repository unique identifier

Type:

RepositoryId | None

Examples

Configuration class provides additional method in order to handle application configuration. Since this class is derived from built-in configparser.RawConfigParser class, the same flow is applicable here. Nevertheless, it is recommended to use from_path() class method which also calls initialization methods:

>>> from pathlib import Path
>>>
>>> configuration = Configuration.from_path(Path("/etc/ahriman.ini"), RepositoryId("x86_64", "aur-clone"))
>>> repository_name = configuration.get("repository", "name")
>>> makepkg_flags = configuration.getlist("build", "makepkg_flags")

The configuration instance loaded in this way will contain only sections which are defined for the specified architecture according to the merge rules. Moreover, the architecture names will be removed from section names.

In order to get current settings, the check_loaded() method can be used. This method will raise an ahriman.core.exceptions.InitializeError in case if configuration was not yet loaded:

>>> path, repository_id = configuration.check_loaded()

default constructor. In the most cases must not be called directly

Parameters:

allow_no_value (bool, optional) – copies configparser.RawConfigParser behaviour. In case if it is set to True, the keys without values will be allowed (Default value = False)

check_loaded() tuple[Path, RepositoryId]

check if service was actually loaded

Returns:

configuration root path and architecture if loaded

Return type:

tuple[Path, RepositoryId]

Raises:

InitializeError – in case if architecture and/or path are not set

dump() dict[str, dict[str, str]]

dump configuration to dictionary

Returns:

configuration dump for specific architecture

Return type:

dict[str, dict[str, str]]

classmethod from_path(path: Path, repository_id: RepositoryId) Self

constructor with full object initialization

Parameters:
  • path (Path) – path to root configuration file

  • repository_id (RepositoryId) – repository unique identifier

Returns:

configuration instance

Return type:

Self

gettype(section: str, repository_id: RepositoryId, *, fallback: str | None = None) tuple[str, str]

get type variable with fallback to old logic. Despite the fact that it has same semantics as other get* methods, but it has different argument list

Parameters:
  • section (str) – section name

  • repository_id (RepositoryId) – repository unique identifier

  • fallback (str | None, optional) – optional fallback type if any. If set, second element of the tuple will be always set to this value (Default value = None)

Returns:

section name and found type name

Return type:

tuple[str, str]

Raises:

configparser.NoSectionError – in case if no section found

load(path: Path) None

fully load configuration

Parameters:

path (Path) – path to root configuration file

load_includes(path: Path | None = None) None

load configuration includes from specified path

Parameters:

path (Path | None, optional) – path to directory with include files. If none set, the default path will be used (Default value = None)

merge_sections(repository_id: RepositoryId) None

merge architecture and repository specific sections into main configuration

Parameters:

repository_id (RepositoryId) – repository unique identifier

override_sections(section: str, repository_id: RepositoryId) list[str]

extract override sections

Parameters:
  • section (str) – section name

  • repository_id (RepositoryId) – repository unique identifier

Returns:

architecture and repository specific sections in correct order

Return type:

list[str]

reload() None

reload configuration if possible or raise exception otherwise

static section_name(section: str, *suffixes: str | None) str

generate section name for sections which depends on context

Parameters:
  • section (str) – section name

  • *suffixes (str | None) – session suffix, e.g. repository architecture

Returns:

correct section name for repository specific section

Return type:

str

set_option(section: str, option: str, value: str) None

set option. Unlike default configparser.RawConfigParser.set() it also creates section if it does not exist

Parameters:
  • section (str) – section name

  • option (str) – option name

  • value (str) – option value as string in parsable format

property architecture: str

repository architecture for backward compatibility

Returns:

repository architecture

Return type:

str

property include: Path

get full path to include directory

Returns:

path to directory with configuration includes

Return type:

Path

property logging_path: Path

get full path to logging configuration

Returns:

path to logging configuration

Return type:

Path

property repository_name: str

repository name for backward compatibility

Returns:

repository name

Return type:

str

property repository_paths: RepositoryPaths

construct RepositoryPaths instance based on the configuration

Returns:

repository paths instance

Return type:

RepositoryPaths

ahriman.core.configuration.schema module

ahriman.core.configuration.shell_interpolator module

class ShellInterpolator

Bases: Interpolation

custom string interpolator, because we cannot use defaults argument due to config validation

before_get(parser: MutableMapping[str, Mapping[str, str]], section: str, option: str, value: str, defaults: Mapping[str, str]) str

interpolate option value

Parameters:
  • parser (MutableMapping[str, Mapping[str, str]]) – option parser

  • section (str) – section name

  • option (str) – option name

  • value (str) – source (not-converted) value

  • defaults (Mapping[str, str]) – default values

Returns:

substituted value

Return type:

str

ahriman.core.configuration.validator module

class Validator(*args: Any, **kwargs: Any)

Bases: Validator

class which defines custom validation methods for the service configuration

configuration

configuration instance

Type:

Configuration

default constructor

Parameters:
  • configuration (Configuration) – configuration instance used for extraction

  • *args (Any) – positional arguments to be passed to base validator

  • **kwargs (Any) – keyword arguments to be passed to base validator

types_mapping = {'binary': ('binary', (<class 'bytes'>, <class 'bytearray'>), ()), 'boolean': ('boolean', (<class 'bool'>,), ()), 'container': ('container', (<class 'collections.abc.Container'>,), (<class 'str'>,)), 'date': ('date', (<class 'datetime.date'>,), ()), 'datetime': ('datetime', (<class 'datetime.datetime'>,), ()), 'dict': ('dict', (<class 'collections.abc.Mapping'>,), ()), 'float': ('float', (<class 'float'>, (<class 'int'>,)), ()), 'integer': ('integer', ((<class 'int'>,),), ()), 'list': ('list', (<class 'collections.abc.Sequence'>,), (<class 'str'>,)), 'number': ('number', ((<class 'int'>,), <class 'float'>), (<class 'bool'>,)), 'path': ('path', (<class 'pathlib.Path'>,), ()), 'set': ('set', (<class 'set'>,), ()), 'string': ('string', (<class 'str'>,), ())}

This mapping holds all available constraints for the type rule and their assigned TypeDefinition.

Module contents