ahriman.core.triggers package

Submodules

ahriman.core.triggers.trigger module

class Trigger(repository_id: RepositoryId, configuration: Configuration)

Bases: LazyLogging

trigger base class

CONFIGURATION_SCHEMA

(class attribute) configuration schema template

Type:

ConfigurationSchema

CONFIGURATION_SCHEMA_FALLBACK

(class attribute) optional fallback option for defining configuration schema type used

Type:

str | None

configuration

configuration instance

Type:

Configuration

repository_id

repository unique identifier

Type:

RepositoryId

Examples

This class must be used in order to create own extension. Basically idea is the following:

>>> class CustomTrigger(Trigger):
>>>     def on_result(self, result: Result, packages: list[Package]) -> None:
>>>         perform_some_action()

Having this class you can pass it to configuration and it will be run on action:

>>> from ahriman.core.triggers import TriggerLoader
>>>
>>> configuration = Configuration()
>>> configuration.set_option("build", "triggers", "my.awesome.package.CustomTrigger")
>>>
>>> loader = TriggerLoader.load(RepositoryId("x86_64", "aur-clone"), configuration)
>>> loader.on_result(Result(), [])

default constructor

Parameters:
classmethod configuration_schema(repository_id: RepositoryId, configuration: Configuration | None) dict[str, dict[str, Any]]

configuration schema based on supplied service configuration

Notes

Schema must be in cerberus format, for details and examples you can check built-in triggers.

Parameters:
  • repository_id (str) – repository unique identifier

  • configuration (Configuration | None) – configuration instance. If set to None, the default schema should be returned

Returns:

configuration schema in cerberus format

Return type:

ConfigurationSchema

classmethod configuration_sections(configuration: Configuration) list[str]

extract configuration sections from configuration

Parameters:

configuration (Configuration) – configuration instance

Returns:

read configuration sections belong to this trigger

Return type:

list[str]

Examples

This method can be used in order to extract specific configuration sections which are set by user, e.g. from sources:

>>> @classmethod
>>> def configuration_sections(cls, configuration: Configuration) -> list[str]:
>>>     return configuration.getlist("report", "target", fallback=[])
on_result(result: Result, packages: list[Package]) None

trigger action which will be called after build process with process result

Parameters:
  • result (Result) – build result

  • packages (list[Package]) – list of all available packages

on_start() None

trigger action which will be called at the start of the application

on_stop() None

trigger action which will be called before the stop of the application

property architecture: str

repository architecture for backward compatibility

Returns:

repository architecture

Return type:

str

ahriman.core.triggers.trigger_loader module

class TriggerLoader

Bases: LazyLogging

trigger loader class

triggers

list of loaded triggers according to the configuration

Type:

list[Trigger]

Examples

This class more likely must not be used directly, but the usual workflow is the following:

>>> configuration = Configuration()  # create configuration
>>> configuration.set_option("build", "triggers", "ahriman.core.report.ReportTrigger")  # set class for load

Having such configuration you can create instance of the loader:

>>> loader = TriggerLoader.load(RepositoryId("x86_64", "aur-clone"), configuration)
>>> print(loader.triggers)

After that you are free to run triggers:

>>> loader.on_result(Result(), [])

default constructor

static known_triggers(configuration: Configuration) list[str]

read configuration and return list of known triggers. Unlike selected_triggers() this option is used mainly for configuration and validation and mentioned triggers are not being executed automatically

Parameters:

configuration (Configuration) – configuration instance

Returns:

list of registered, but not enabled, triggers

Return type:

list[str]

classmethod load(repository_id: RepositoryId, configuration: Configuration) Self

create instance from configuration

Parameters:
Returns:

fully loaded trigger instance

Return type:

Self

load_trigger(module_path: str, repository_id: RepositoryId, configuration: Configuration) Trigger

load trigger by module path

Parameters:
  • module_path (str) – module import path to load

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

Returns:

loaded trigger based on settings

Return type:

Trigger

Raises:

ExtensionError – in case if trigger could not be instantiated

load_trigger_class(module_path: str) type[Trigger]

load trigger class by module path

Parameters:

module_path (str) – module import path to load

Returns:

loaded trigger type by module path

Return type:

type[Trigger]

Raises:

ExtensionError – in case if module cannot be loaded from the specified module path or is not a trigger

on_result(result: Result, packages: list[Package]) None

run trigger with result of application run

Parameters:
  • result (Result) – build result

  • packages (list[Package]) – list of all available packages

on_start() None

run triggers on load

on_stop() None

run triggers before the application exit

static selected_triggers(configuration: Configuration) list[str]

read configuration and return triggers which are set by settings

Parameters:

configuration (Configuration) – configuration instance

Returns:

list of triggers according to configuration

Return type:

list[str]

Module contents