PacmanRepository

Manage repository sections in the target’s pacman configuration as root. Use repositories and signing keys that you trust.

class rmote.tools.pacman_repository.PacmanRepository[source]

Bases: Tool

Manage Arch Linux repository sections and GPG keys.

Repository sections are read from and written to /etc/pacman.conf. GPG key files are stored in /etc/pacman.d/. All operations are idempotent and require root.

Every operation needs the /etc/pacman.conf configuration of Arch Linux. A target without it refuses with NotImplementedError instead of writing a file that nothing reads.

Update pacman.conf inside a disposable Arch Linux container. The example repository is only written to disk; it is not contacted:

>>> from rmote.tools import FileSystem
>>> remote = getfixture("arch_tool")
>>> options = dict(servers=["https://repo.example/$arch"], sig_level="Required DatabaseOptional")
>>> remote(PacmanRepository.present, "example", **options).changed
True
>>> remote(PacmanRepository.present, "example", **options).changed
False
>>> "[example]" in remote(FileSystem.read_str, "/etc/pacman.conf")
True
>>> remote(PacmanRepository.absent, "example").changed
True
>>> remote(PacmanRepository.absent, "example").changed
False
static absent(name)[source]

Remove the repository section name from /etc/pacman.conf.

Parameters:

name (Text) – Repository section name to remove.

Return type:

Result

Returns:

Result indicating whether pacman.conf was modified.

static key(name, data)[source]

Write a GPG key to /etc/pacman.d/{name}.

Idempotent — the file is left untouched if it already contains identical bytes.

Parameters:
  • name (Text) – Filename to write the key under (e.g. "blackarch.gpg").

  • data (bytes) – Raw key bytes.

Return type:

Result

Returns:

Result indicating whether the key was written.

static present(name, *, servers, sig_level='Optional TrustAll')[source]

Ensure a repository section is present in /etc/pacman.conf.

If the section already exists with the same content it is left unchanged. If it exists with different content it is updated in-place. Otherwise it is appended at the end of the file.

Parameters:
  • name (Text) – Repository section name (e.g. "blackarch").

  • servers (list[Text]) – One or more server URLs for the repository.

  • sig_level (Text) – pacman SigLevel value. Defaults to "Optional TrustAll".

Return type:

Result

Returns:

Result indicating whether pacman.conf was modified.

Types

class rmote.tools.pacman_repository.Result(name, changed)[source]

Bases: object

changed: bool
name: str