AptRepository

Manage apt source files and repository keys on the target as root. After changing a source, refresh the package index with Apt.update.

class rmote.tools.apt_repository.AptRepository[source]

Bases: Tool

Manage APT repository sources and GPG keys on Debian/Ubuntu.

Repository sources are written as DEB822 .sources files under /etc/apt/sources.list.d/. GPG keyrings are stored in /etc/apt/keyrings/. All operations are idempotent and require root.

Every operation needs the /etc/apt configuration of Debian and Ubuntu. A target without it refuses with NotImplementedError instead of writing a directory that nothing reads.

Write and remove a real source definition inside a disposable Debian container. The example URI is only written to disk; it is not contacted:

>>> from rmote.tools import FileSystem
>>> remote = getfixture("debian_tool")
>>> options = dict(uris=["https://repo.example/debian"], suites=["stable"], components=["main"])
>>> remote(AptRepository.present, "example", **options).changed
True
>>> remote(AptRepository.present, "example", **options).changed
False
>>> "Suites: stable" in remote(FileSystem.read_str, "/etc/apt/sources.list.d/example.sources")
True
>>> remote(AptRepository.absent, "example").changed
True
>>> remote(AptRepository.absent, "example").changed
False
static absent(name)[source]

Remove the DEB822 .sources file for name, if it exists.

Parameters:

name (Text) – Repository label (the {name}.sources filename stem).

Return type:

Result

Returns:

Result indicating whether the file was removed.

static key(name, data)[source]

Install a GPG signing key to /etc/apt/keyrings/{name}.

The operation is idempotent — if the file already contains identical bytes it is left untouched.

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

  • data (bytes) – Raw key bytes (binary DER or ASCII-armoured GPG key).

Return type:

Result

Returns:

Result indicating whether the key was written.

static present(name, *, types=('deb',), uris, suites, components, signed_by='')[source]

Ensure a DEB822 .sources file is configured for name.

Writes /etc/apt/sources.list.d/{name}.sources. The operation is idempotent — if the file already contains the expected content it is left untouched.

Parameters:
  • name (Text) – Repository label used as the filename stem.

  • types (Iterable[Text]) – Package types — typically ("deb",) for binary packages or ("deb-src",) for source packages.

  • uris (Iterable[Text]) – Repository base URIs (e.g. ("https://download.docker.com/linux/ubuntu",)).

  • suites (Iterable[Text]) – Distribution suites (e.g. ("noble",)).

  • components (Iterable[Text]) – Repository components (e.g. ("stable",)).

  • signed_by (Text) – Absolute path to the GPG keyring that signs this repository.

Return type:

Result

Returns:

Result indicating whether the file was created or updated.

Types

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

Bases: object

changed: bool
name: str