ahriman.core.alpm package

Subpackages

Submodules

ahriman.core.alpm.pacman module

class Pacman(repository_id: RepositoryId, configuration: Configuration, *, refresh_database: PacmanSynchronization)

Bases: LazyLogging

alpm wrapper

configuration

configuration instance

Type:

Configuration

refresh_database

synchronize local cache to remote

Type:

PacmanSynchronization

repository_id

repository unique identifier

Type:

RepositoryId

repository_paths

repository paths instance

Type:

RepositoryPaths

Parameters:
database_copy(handle: pyalpm.Handle, database: pyalpm.DB, pacman_root: Path, *, use_ahriman_cache: bool) None

copy database from the operating system root to the ahriman local home

Parameters:
  • handle (Handle) – pacman handle which will be used for database copying

  • database (DB) – pacman database instance to be copied

  • pacman_root (Path) – operating system pacman root

  • use_ahriman_cache (bool) – use local ahriman cache instead of system one

database_init(handle: pyalpm.Handle, repository: str, architecture: str) pyalpm.DB

create database instance from pacman handler and set its properties

Parameters:
  • handle (Handle) – pacman handle which will be used for database initializing

  • repository (str) – pacman repository name (e.g. core)

  • architecture (str) – repository architecture

Returns:

loaded pacman database instance

Return type:

DB

database_sync(handle: pyalpm.Handle, *, force: bool) None

sync local database

Parameters:
  • handle (Handle) – pacman handle which will be used for database sync

  • force (bool) – force database synchronization (same as pacman -Syy)

files(packages: Iterable[str]) dict[str, set[str]]

extract list of known packages from the databases

Parameters:

packages (Iterable[str]) – filter by package names

Returns:

map of package name to its list of files

Return type:

dict[str, set[str]]

package(package_name: str) Iterator[pyalpm.Package]

retrieve list of the packages from the repository by name

Parameters:

package_name (str) – package name to search

Yields:

Package – list of packages which were returned by the query

packages() set[str]

get list of packages known for alpm

Returns:

list of package names

Return type:

set[str]

provided_by(package_name: str) Iterator[pyalpm.Package]

search through databases and emit packages which provides the package_name

Parameters:

package_name (str) – package name to search

Yields:

Package – list of packages which were returned by the query

property handle: pyalpm.Handle

pyalpm handle

Returns:

generated pyalpm handle instance

Return type:

Handle

ahriman.core.alpm.pacman_database module

class PacmanDatabase(database: pyalpm.DB, configuration: Configuration)

Bases: SyncHttpClient

implementation for database sync, because pyalpm is not always enough

LAST_MODIFIED_HEADER

last modified header name

Type:

str

database

pyalpm database object

Type:

DB

repository_paths

repository paths instance

Type:

RepositoryPaths

sync_files_database

sync files database

Type:

bool

Parameters:
  • database (DB) – pyalpm database object

  • configuration (Configuration) – configuration instance

static copy(remote_path: Path, local_path: Path) None

copy local database file

Parameters:
  • remote_path (Path) – path to source (remote) file

  • local_path (Path) – path to locally stored file

download(url: str, local_path: Path) None

download remote file and store it to local path with the correct last modified headers

Parameters:
  • url (str) – remote url to request file

  • local_path (Path) – path to locally stored file

Raises:

PacmanError – in case if no last-modified header was found

is_outdated(url: str, local_path: Path) bool

check if local file is outdated

Parameters:
  • url (str) – remote url to request last modified header

  • local_path (Path) – path to locally stored file

Returns:

True in case if remote file is newer than local file

Return type:

bool

Raises:

PacmanError – in case if no last-modified header was found

sync(*, force: bool) None

sync packages and files databases

Parameters:

force (bool) – force database synchronization (same as pacman -Syy)

sync_files(*, force: bool) None

sync files by using http request

Parameters:

force (bool) – force database synchronization (same as pacman -Syy)

Raises:

PacmanError – on operation error (invalid scheme or incomplete configuration)

sync_packages(*, force: bool) None

sync packages by using built-in pyalpm methods

Parameters:

force (bool) – force database synchronization (same as pacman -Syy)

ahriman.core.alpm.pkgbuild_parser module

class PkgbuildParser(stream: IO[str])

Bases: shlex

simple pkgbuild reader implementation in pure python, because others suck.

What is it:

  1. Simple PKGBUILD parser written in python.

  2. No shell execution, so it is free from random shell attacks.

  3. Able to parse simple constructions (assignments, comments, functions, arrays).

What it is not:

  1. Fully functional shell parser.

  2. Shell executor.

  3. No parameter expansion.

For more details what does it support, please, consult with the test cases.

Examples

This class is heavily based on shlex parser, but instead of strings operates with the ahriman.models.pkgbuild_patch.PkgbuildPatch objects. The main way to use it is to call parse() function and collect parsed objects, e.g.:

>>> parser = PkgbuildParser(StringIO("input string"))
>>> for patch in parser.parse():
>>>     print(f"{patch.key} = {patch.value}")

It doesn’t store the state of the fields (but operates with the shlex parser state), so no shell post-processing is performed (e.g. variable substitution).

Parameters:

stream (IO[str]) – input stream containing PKGBUILD content

parse() Iterator[PkgbuildPatch]

parse source stream and yield parsed entries

Yields:

PkgbuildPatch – extracted a PKGBUILD node

class PkgbuildToken(*values)

Bases: StrEnum

well-known tokens dictionary

ArrayEnds

array ends token

Type:

PkgbuildToken

ArrayStarts

array starts token

Type:

PkgbuildToken

Comma

comma token

Type:

PkgbuildToken

Comment

comment token

Type:

PkgbuildToken

FunctionDeclaration

function declaration token

Type:

PkgbuildToken

FunctionEnds

function ends token

Type:

PkgbuildToken

FunctionStarts

function starts token

Type:

PkgbuildToken

NewLine

new line token

Type:

PkgbuildToken

ahriman.core.alpm.repo module

class Repo(name: str, paths: RepositoryPaths, sign_args: list[str], root: Path | None = None)

Bases: LazyLogging

repo-add and repo-remove wrapper

name

repository name

Type:

str

root

repository root

Type:

Path

sign_args

additional args which have to be used to sign repository archive

Type:

list[str]

uid

uid of the repository owner user

Type:

int

Parameters:
  • name (str) – repository name

  • paths (RepositoryPaths) – repository paths instance

  • sign_args (list[str]) – additional args which have to be used to sign repository archive

  • root (Path | None, optional) – repository root. If none set, the default will be used (Default value = None)

add(path: Path) None

add new package to repository

Parameters:

path (Path) – path to archive to add

init() None

create empty repository database. It just calls add with empty arguments

remove(package_name: str, filename: Path) None

remove package from repository

Parameters:
  • package_name (str) – package name to remove

  • filename (Path) – package filename to remove

property repo_path: Path

get full path to the repository database

Returns:

path to repository database

Return type:

Path

Module contents