Apt

Manage Debian or Ubuntu packages with apt-get as root. Refresh the package index with update before installing a package. See Quickstart for installation and repeated-run checks.

class rmote.tools.apt.Apt[source]

Bases: Tool

Manage Debian/Ubuntu packages via apt-get. Requires root on the remote host.

Every operation that changes packages runs apt-get. A target without it refuses with NotImplementedError. The installed set is read from /var/lib/dpkg/status, and an absent file reads as no packages.

Install and remove a package in a disposable Debian container. remote is the fixture’s synchronous RPC callable (like a Connection):

>>> remote = getfixture("debian_tool")
>>> remote(Apt.update)
True
>>> remote(Apt.package, "nano").changed
True
>>> remote(Apt.package, "nano").changed
False
>>> remote(Apt.package, "nano", state=State.ABSENT).changed
True
>>> remote(Apt.package, "nano", state=State.ABSENT).changed
False
async classmethod converge(*packages)[source]

Apply each Package.state; string arguments default to PRESENT.

Parameters:

*packages (Text | Package) – Package names, name=version strings, or Package instances.

Return type:

list[Result]

Returns:

List of Result objects, one per package, in the same order as the input.

async classmethod package(package, state=None)[source]

Install, remove, or upgrade a single package.

Parameters:
  • package (Text | Package) – Package name, name=version string, or a Package instance.

  • state (State | getint | None) – Desired state - State.PRESENT (install if absent), State.ABSENT (purge if installed), or State.LATEST (install or upgrade to candidate version). An explicit state overrides Package.state. If omitted, use Package.state for objects or PRESENT for strings.

Return type:

Result

Returns:

Result with the package name, installed version, and whether the system was changed.

Raises:

RuntimeError – If the underlying apt-get invocation fails.

async static update(ttl=-1)[source]

Run apt-get update, with optional TTL-based skipping.

Parameters:

ttl (getint | getdouble) – Minimum age in seconds of the last successful update before re-running. -1 (default) always runs the update.

Return type:

bool

Returns:

True if apt-get update was executed, False if the cache is fresher than ttl seconds.

Raises:

RuntimeError – If apt-get update exits with a non-zero status.

Types

class rmote.tools.apt.State(*values)[source]

Bases: IntEnum

ABSENT = 1
LATEST = 2
PRESENT = 0
class rmote.tools.apt.Package(name, state=State.PRESENT, version='')[source]

Bases: object

classmethod from_string(s, state=State.PRESENT)[source]
Return type:

Package

name: str
classmethod parse(s, state=None)[source]

Use the explicit state, then Package.state, then PRESENT.

Return type:

Package

state: int = 0
version: str = ''
class rmote.tools.apt.Result(name, changed, version='')[source]

Bases: object

changed: bool
classmethod from_package(package, changed)[source]
Return type:

Result

name: str
version: str = ''