ahriman.application.handlers package

Submodules

ahriman.application.handlers.add module

class Add

Bases: Handler

add packages handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.backup module

class Backup

Bases: Handler

backup packages handler

static get_paths(configuration: Configuration) set[Path]

extract paths to back up

Parameters:

configuration (Configuration) – configuration instance

Returns:

map of the filesystem paths

Return type:

set[Path]

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.change module

class Change

Bases: Handler

package changes handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.clean module

class Clean

Bases: Handler

clean caches handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.daemon module

class Daemon

Bases: Handler

daemon packages handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.dump module

class Dump

Bases: Handler

dump configuration handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.handler module

class Handler

Bases: object

base handler class for command callbacks

ALLOW_MULTI_ARCHITECTURE_RUN

(class attribute) allow running with multiple architectures

Type:

bool

Examples

Wrapper for all command line actions, though each derived class implements run() method, it usually must not be called directly. The recommended way is to call execute() class method, e.g.:

>>> from ahriman.application.handlers import Add
>>>
>>> Add.execute(args)
classmethod call(args: Namespace, repository_id: RepositoryId) bool

additional function to wrap all calls for multiprocessing library

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

Returns:

True on success, False otherwise

Return type:

bool

static check_if_empty(enabled: bool, predicate: bool) None

check condition and flag and raise ExitCode exception in case if it is enabled and condition match

Parameters:
  • enabled (bool) – if False no check will be performed

  • predicate (bool) – indicates condition on which exception should be thrown

Raises:

ExitCode – if result is empty and check is enabled

classmethod execute(args: Namespace) int

execute function for all aru

Parameters:

args (argparse.Namespace) – command line args

Returns:

0 on success, 1 otherwise

Return type:

int

Raises:

MultipleArchitecturesError – if more than one architecture supplied and no multi architecture supported

static repositories_extract(args: Namespace) list[RepositoryId]

get known architectures

Parameters:

args (argparse.Namespace) – command line args

Returns:

list of repository names and architectures for which tree is created

Return type:

list[RepositoryId]

Raises:

MissingArchitectureError – if no architecture set and automatic detection is not allowed or failed

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

Raises:

NotImplementedError – not implemented method

ahriman.application.handlers.help module

class Help

Bases: Handler

help handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.key_import module

class KeyImport

Bases: Handler

key import packages handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.patch module

class Patch

Bases: Handler

patch control handler

static patch_create_from_diff(sources_dir: Path, architecture: str, track: list[str]) tuple[str, PkgbuildPatch]

create PKGBUILD plain diff patches from sources directory

Parameters:
  • sources_dir (Path) – path to directory with the package sources

  • architecture (str) – repository architecture

  • track (list[str]) – track files which match the glob before creating the patch

Returns:

package base and created PKGBUILD patch based on the diff from master HEAD to current files

Return type:

tuple[str, PkgbuildPatch]

static patch_create_from_function(variable: str, patch_path: Path | None) PkgbuildPatch

create single-function patch set for the package base

Parameters:
  • variable (str) – function or variable name inside PKGBUILD

  • patch_path (Path | None) – optional path to patch content. If not set, it will be read from stdin

Returns:

created patch for the PKGBUILD function

Return type:

PkgbuildPatch

static patch_set_create(application: Application, package_base: str, patch: PkgbuildPatch) None

create patch set for the package base

Parameters:
  • application (Application) – application instance

  • package_base (str) – package base

  • patch (PkgbuildPatch) – patch descriptor

static patch_set_list(application: Application, package_base: str | None, variables: list[str] | None, exit_code: bool) None

list patches available for the package base

Parameters:
  • application (Application) – application instance

  • package_base (str | None) – package base

  • variables (list[str] | None) – extract patches only for specified PKGBUILD variables

  • exit_code (bool) – exit with error on empty search result

static patch_set_remove(application: Application, package_base: str, variables: list[str] | None) None

remove patch set for the package base

Parameters:
  • application (Application) – application instance

  • package_base (str) – package base

  • variables (list[str] | None) – remove patches only for specified PKGBUILD variables

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.rebuild module

class Rebuild

Bases: Handler

make world handler

static extract_packages(application: Application, status: BuildStatusEnum | None, *, from_database: bool) list[Package]

extract packages from database file

Parameters:
  • application (Application) – application instance

  • status (BuildStatusEnum | None) – optional filter by package status

  • from_database (bool) – extract packages from database instead of repository filesystem

Returns:

list of packages which were stored in database

Return type:

list[Package]

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.remove module

class Remove

Bases: Handler

remove packages handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.remove_unknown module

class RemoveUnknown

Bases: Handler

remove unknown packages handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.repositories module

class Repositories

Bases: Handler

repositories listing handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.restore module

class Restore

Bases: Handler

restore packages handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.run module

class Run

Bases: Handler

multicommand handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

static run_command(command: list[str], parser: ArgumentParser) bool

run command specified by the argument

Parameters:
  • command (list[str]) – command to run

  • parser (argparse.ArgumentParser) – generated argument parser

Returns:

status of the command

Return type:

bool

ahriman.application.handlers.search module

class Search

Bases: Handler

packages search handler

SORT_FIELDS

(class attribute) allowed fields to sort the package list

Type:

set[str]

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

static sort(packages: Iterable[AURPackage], sort_by: str) list[AURPackage]

sort package list by specified field

Parameters:
  • packages (Iterable[AURPackage]) – packages list to sort

  • sort_by (str) – AUR package field name to sort by

Returns:

sorted list for packages

Return type:

list[AURPackage]

Raises:

OptionError – if search fields is not in list of allowed ones

ahriman.application.handlers.service_updates module

class ServiceUpdates

Bases: Handler

service updates handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.setup module

class Setup

Bases: Handler

setup handler

ARCHBUILD_COMMAND_PATH

(class attribute) default devtools command

Type:

Path

MIRRORLIST_PATH

(class attribute) path to pacman default mirrorlist (used by multilib repository)

Type:

Path

SUDOERS_DIR_PATH

(class attribute) path to sudoers.d includes directory

Type:

Path

static build_command(root: Path, repository_id: RepositoryId) Path

generate build command name

Parameters:
  • root (Path) – root directory for the build command (must be root of the repository)

  • repository_id (RepositoryId) – repository unique identifier

Returns:

valid devtools command name

Return type:

Path

static configuration_create_ahriman(args: Namespace, repository_id: RepositoryId, root: Configuration) None

create service specific configuration

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • root (Configuration) – root configuration instance

static configuration_create_devtools(repository_id: RepositoryId, source: Path, mirror: str | None, multilib: bool, repository_server: str) None

create configuration for devtools based on source configuration

Notes

devtools does not allow to specify the pacman configuration, thus we still have to use configuration in /usr

Parameters:
  • repository_id (RepositoryId) – repository unique identifier

  • source (Path) – path to source configuration file

  • mirror (str | None) – link to package server mirror

  • multilib (bool) – add or do not multilib repository to the configuration

  • repository_server (str) – url of the repository

static configuration_create_makepkg(packager: str, makeflags_jobs: bool, paths: RepositoryPaths) None

create configuration for makepkg

Parameters:
  • packager (str) – packager identifier (e.g. name, email)

  • makeflags_jobs (bool) – set MAKEFLAGS variable to number of cores

  • paths (RepositoryPaths) – repository paths instance

static configuration_create_sudo(paths: RepositoryPaths, repository_id: RepositoryId) None

create configuration to run build command with sudo without password

Parameters:
static executable_create(paths: RepositoryPaths, repository_id: RepositoryId) None

create executable for the service

Parameters:
classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.shell module

class Shell

Bases: Handler

python shell handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.sign module

class Sign

Bases: Handler

(re-)sign handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.status module

class Status

Bases: Handler

package status handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.status_update module

class StatusUpdate

Bases: Handler

status update handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.structure module

class Structure

Bases: Handler

dump repository structure handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.tree_migrate module

class TreeMigrate

Bases: Handler

tree migration handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

static tree_move(from_tree: RepositoryPaths, to_tree: RepositoryPaths) None

move files between trees. Trees must be created in advance

Parameters:

ahriman.application.handlers.triggers module

class Triggers

Bases: Handler

triggers handlers

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.unsafe_commands module

class UnsafeCommands

Bases: Handler

unsafe command help parser

static check_unsafe(command: list[str], unsafe_commands: list[str], parser: ArgumentParser) None

check if command is unsafe

Parameters:
  • command (str) – command to check

  • unsafe_commands (list[str]) – list of unsafe commands

  • parser (argparse.ArgumentParser) – generated argument parser

static get_unsafe_commands(parser: ArgumentParser) list[str]

extract unsafe commands from argument parser

Parameters:

parser (argparse.ArgumentParser) – generated argument parser

Returns:

list of commands with default unsafe flag

Return type:

list[str]

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.update module

class Update

Bases: Handler

package update handler

static log_fn(application: Application, dry_run: bool) Callable[[str], None]

package updates log function

Parameters:
  • application (Application) – application instance

  • dry_run (bool) – do not perform update itself

Returns:

in case if dry_run is set it will return print, logger otherwise

Return type:

Callable[[str], None]

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.users module

class Users

Bases: Handler

user management handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

static user_create(args: Namespace) User

create user descriptor from arguments

Parameters:

args (argparse.Namespace) – command line args

Returns:

built user descriptor

Return type:

User

Raises:

PasswordError – password input is invalid

ahriman.application.handlers.validate module

class Validate

Bases: Handler

configuration validator handler

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

static schema(repository_id: RepositoryId, configuration: Configuration) dict[str, dict[str, Any]]

get schema with triggers

Parameters:
Returns:

configuration validation schema

Return type:

ConfigurationSchema

static schema_erase_required(schema: dict[str, dict[str, Any]]) dict[str, dict[str, Any]]

recursively remove required field from supplied cerberus schema

Parameters:

schema (ConfigurationSchema) – source schema from which required field must be removed

Returns:

schema without required fields. Note, that source schema will be modified in-place

Return type:

ConfigurationSchema

static schema_merge(source: dict[str, Any], schema: dict[str, Any]) dict[str, Any]
merge child schema into source. In case if source already contains values, new keys will be added

(possibly with overrides - in case if such key already set also)

Parameters:
  • source (dict[str, Any]) – source (current) schema into which will be merged

  • schema (dict[str, Any]) – new schema to be merged

Returns:

schema with added elements from source schema if they were set before and not presented in the new one. Note, that schema will be modified in-place

Return type:

dict[str, Any]

ahriman.application.handlers.versions module

class Versions

Bases: Handler

version handler

PEP423_PACKAGE_NAME

(class attribute) special regex for valid PEP423 package name

Type:

str

static package_dependencies(root: str) Generator[tuple[str, str], None, None]

extract list of ahriman package dependencies installed into system with their versions

Parameters:

root (str) – root package name

Yields:

tuple[str, str] – map of installed dependency to its version

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

ahriman.application.handlers.web module

class Web

Bases: Handler

web server handler

static extract_arguments(args: Namespace, configuration: Configuration) Generator[str, None, None]

extract list of arguments used for current command, except for command specific ones

Parameters:
  • args (argparse.Namespace) – command line args

  • configuration (Configuration) – configuration instance

Yields:

str – command line arguments which were used for this specific command

classmethod run(args: Namespace, repository_id: RepositoryId, configuration: Configuration, *, report: bool) None

callback for command line

Parameters:
  • args (argparse.Namespace) – command line args

  • repository_id (RepositoryId) – repository unique identifier

  • configuration (Configuration) – configuration instance

  • report (bool) – force enable or disable reporting

Module contents