apt module¶
AptAutoremovable
¶
Packages apt autoremove would remove, as AptPackageInfo dicts.
Commands:
apt-get --just-print autoremove 2>/dev/null
Returns:
list[AptPackageInfo]
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_apt_autoremovable.py.
AptHeldPackages
¶
Packages marked as held, as a sorted list of AptPackageInfo dicts.
Commands:
apt-mark showhold
Returns:
list[AptPackageInfo]
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_apt_held_packages.py.
AptKey
¶
Attributes:
| Name | Type | Description |
|---|---|---|
id |
The key id (the last 16 hex digits of the fingerprint), the identity a keyring file lists the key under. |
|
validity |
GPG's validity letter for the key ( |
|
length |
The key length in bits (e.g. 4096). |
|
fingerprint |
The full fingerprint, when a |
|
uid_hash |
The hash of the user id, when a |
|
uid |
The user id string (name, comment and email), when a
|
|
subkeys |
The key's subkeys as further |
AptKeys
¶
The GPG keys available to APT, as a list of AptKey dicts.
Commands:
find "/etc/apt/trusted.gpg.d" "/etc/apt/keyrings" "/usr/share/keyrings" -type f \( -name '*.gpg' -o -name '*.kbx' \) 2>/dev/null -exec sh -c 'echo "KEYRING:$1"; gpg --list-keys --with-colons --keyring "$1" --no-default-keyring 2>/dev/null || true' _ {} \; ; find "/etc/apt/trusted.gpg.d" "/etc/apt/keyrings" "/usr/share/keyrings" -type f -name '*.asc' 2>/dev/null -exec sh -c 'echo "KEYRING:$1"; gpg --with-colons "$1" 2>/dev/null || true' _ {} \;
Returns:
list[AptKey]
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_apt_keys.py.
AptPackageInfo
¶
Attributes:
| Name | Type | Description |
|---|---|---|
name |
The package name, architecture suffixes ( |
|
versions |
The package's versions, de-duplicated and sorted,
epoch prefixes ( |
AptPackagePolicy
¶
Attributes:
| Name | Type | Description |
|---|---|---|
installed |
The installed version, or None when apt prints
|
|
candidate |
The version |
|
versions |
The version table as |
AptPackageUpgrade
¶
Attributes:
| Name | Type | Description |
|---|---|---|
name |
The package name, architecture suffixes ( |
|
installed |
The currently installed version (the row's
|
|
candidate |
The version |
AptPackages
¶
Installed apt packages, as a list of AptPackageInfo dicts.
Commands:
apt list --installed 2>/dev/null
Returns:
list[AptPackageInfo]
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_apt_packages.py.
AptPolicy
¶
One package's install candidate and origins, as an AptPackagePolicy.
Commands:
LC_ALL=C apt-cache policy <package>
Returns:
AptPackagePolicy | None
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_apt_policy.py.
AptPolicyVersion
¶
Attributes:
| Name | Type | Description |
|---|---|---|
version |
The version string, epoch prefixes ( |
|
priority |
The pin priority apt assigns the version (500 for a
normal repository, 100 for the installed |
|
origins |
The origin lines listed under the version, each with
its leading priority stripped: a repository line like
|
AptSource
¶
Attributes:
| Name | Type | Description |
|---|---|---|
type |
|
|
url |
The repository URL, e.g. |
|
distribution |
The suite/distribution, e.g. |
|
components |
The components, e.g. |
|
options |
The bracketed |
AptSources
¶
The configured apt sources, as a list of AptSource dicts.
Commands:
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; do [ -e "$f" ] || continue; printf "#reemote-aptsource %s\n" "$f"; cat "$f"; echo; done
Returns:
list[AptSource]
Raises:
HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_apt_sources.py.
AptSourcesFile
¶
The current content of one apt sources file, or None when it is absent.
Commands:
test -e <path> && { printf '#reemote-sourcesfile\n'; cat -- <path>; }
Returns:
str | None
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_sources_file.py.
AptUpgradable
¶
Packages with a pending upgrade, as a list of AptPackageUpgrade dicts.
Commands:
apt list --upgradable 2>/dev/null
Returns:
list[AptPackageUpgrade]
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_apt_upgradable.py.
DebPackage
¶
The name and version of a .deb file or an installed dpkg package.
Commands:
test -f <package> && case <package> in *.deb) dpkg -I <package> ;; *) dpkg -s <package> 2>/dev/null || true ;; esac || dpkg -s <package> 2>/dev/null || true
Returns:
DebPackageInfo | None
Raises:
HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_deb.py.
DebPackageInfo
¶
Attributes:
| Name | Type | Description |
|---|---|---|
name |
The package name from the |
|
version |
The package version from the |
auto_remove
async
¶
auto_remove(
ctx: OpContext,
wait_for_lock: bool | int = False,
**kwargs: Any,
) -> AsyncGenerator[Command]
Remove transitive dependencies that are no longer needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
wait_for_lock
|
bool | int
|
Wait for the apt lock instead of
failing instantly; |
False
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated apt autoremove commands. |
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_auto_remove.py.
deb
async
¶
deb(
ctx: OpContext,
src: str,
present: bool = True,
wait_for_lock: bool | int = False,
**kwargs: Any,
) -> AsyncGenerator[Command]
Add/remove a .deb file package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
src
|
str
|
Path to the |
required |
present
|
bool
|
Whether the package should be installed. Defaults to True. |
True
|
wait_for_lock
|
bool | int
|
Wait for the apt lock instead of
failing instantly; |
False
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated apt deb package commands. |
Raises:
CommandNotFoundError, HostConnectionError, ValueError
Examples:
Examples can be found in examples/modules/apt/apt_deb.py.
dist_upgrade
async
¶
dist_upgrade(
ctx: OpContext,
wait_for_lock: bool | int = False,
**kwargs: Any,
) -> AsyncGenerator[Command]
Update all apt packages, employing dist-upgrade.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
wait_for_lock
|
bool | int
|
Wait for the apt lock instead of
failing instantly; |
False
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated apt dist-upgrade commands. |
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_dist_upgrade.py.
key
async
¶
Install a GPG keyring file for APT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
src
|
IO[Any]
|
The key content as a seekable IO-like object on the
control machine (an |
required |
dest
|
str
|
The keyring filename or absolute path on the target host;
a relative name is resolved under |
required |
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated apt GPG keyring commands. |
Raises:
ValueError
Examples:
Examples can be found in examples/modules/apt/apt_key.py.
mark
async
¶
mark(
ctx: OpContext,
packages: str | list[str] | tuple[str, ...],
held: bool = True,
**kwargs: Any,
) -> AsyncGenerator[Command]
Hold packages back from upgrades, or release held ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
packages
|
str | list[str] | tuple[str, ...]
|
Package names to mark; a
single string or a list/tuple. Prefer tuples when building requests
via |
required |
held
|
bool
|
Whether the packages should be held
( |
True
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated apt-mark hold/unhold commands. |
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_mark.py.
packages
async
¶
packages(
ctx: OpContext,
packages: str
| list[str]
| tuple[str, ...]
| None = None,
present: bool = True,
latest: bool = False,
update: bool = False,
upgrade: bool = False,
no_recommends: bool = False,
allow_downgrades: bool = False,
purge: bool = False,
extra_install_args: str | None = None,
extra_uninstall_args: str | None = None,
wait_for_lock: bool | int = False,
**kwargs: Any,
) -> AsyncGenerator[Command]
Install/remove/update apt packages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
packages
|
str | list[str] | tuple[str, ...] | None
|
Packages
to ensure; a single string, a list/tuple, or None. Prefer tuples
when building requests via |
None
|
present
|
bool
|
Whether the packages should be installed. Defaults to True. |
True
|
latest
|
bool
|
Whether to upgrade installed packages without a pinned version. Defaults to False. |
False
|
update
|
bool
|
Run |
False
|
upgrade
|
bool
|
Run |
False
|
no_recommends
|
bool
|
Add |
False
|
allow_downgrades
|
bool
|
Add |
False
|
purge
|
bool
|
When removing ( |
False
|
extra_install_args
|
str | None
|
Additional arguments to the apt install command. Defaults to None. |
None
|
extra_uninstall_args
|
str | None
|
Additional arguments to the apt remove command. Defaults to None. |
None
|
wait_for_lock
|
bool | int
|
Wait for the apt lock instead of
failing instantly; |
False
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated apt package commands. |
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_packages.py.
ppa
async
¶
Add/remove an Ubuntu PPA repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
src
|
str
|
The PPA name, in full |
required |
present
|
bool
|
Whether the repository should exist. Defaults to True. |
True
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated apt PPA repository commands. |
Raises:
None
Examples:
Examples can be found in examples/modules/apt/apt_ppa.py.
repo
async
¶
repo(
ctx: OpContext,
src: str,
present: bool = True,
filename: str | None = None,
**kwargs: Any,
) -> AsyncGenerator[Command]
Add/remove an apt repository line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
src
|
str
|
Apt source string, e.g. |
required |
present
|
bool
|
Whether the repository should exist on the system. Defaults to True. |
True
|
filename
|
str | None
|
Base name under
|
None
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated apt repository line commands. |
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_repo.py.
sources_file
async
¶
sources_file(
ctx: OpContext,
filename: str,
types: str | list[str] | tuple[str, ...] = "deb",
uris: str | list[str] | tuple[str, ...] | None = None,
suites: str | list[str] | tuple[str, ...] | None = None,
components: str
| list[str]
| tuple[str, ...]
| None = None,
architectures: str
| list[str]
| tuple[str, ...]
| None = None,
signed_by: str | None = None,
present: bool = True,
**kwargs: Any,
) -> AsyncGenerator[Command]
Manage a deb822 .sources file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
filename
|
str
|
Base name for the file (without extension); the
|
required |
types
|
str | list[str] | tuple[str, ...]
|
Repository
type(s) -- |
'deb'
|
uris
|
str | list[str] | tuple[str, ...] | None
|
One or more repository URLs. Defaults to None. |
None
|
suites
|
str | list[str] | tuple[str, ...] | None
|
One or
more suite/distribution names (e.g. |
None
|
components
|
str | list[str] | tuple[str, ...] | None
|
One
or more components (e.g. |
None
|
architectures
|
str | list[str] | tuple[str, ...] | None
|
Restrict to specific architectures (e.g. |
None
|
signed_by
|
str | None
|
Absolute path to the keyring file used for signature verification. Defaults to None. |
None
|
present
|
bool
|
Whether the sources file should exist. Defaults to True. |
True
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated apt deb822 sources file commands. |
Raises:
CommandNotFoundError, HostConnectionError, ValueError
Examples:
Examples can be found in examples/modules/apt/apt_sources_file.py.
update
async
¶
update(
ctx: OpContext,
wait_for_lock: bool | int = False,
**kwargs: Any,
) -> AsyncGenerator[Command]
Update apt repositories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
wait_for_lock
|
bool | int
|
Wait for the apt lock instead of
failing instantly; |
False
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated apt update commands. |
Raises:
None
Examples:
Examples can be found in examples/modules/apt/apt_update.py.
upgrade
async
¶
upgrade(
ctx: OpContext,
wait_for_lock: bool | int = False,
**kwargs: Any,
) -> AsyncGenerator[Command]
Upgrade all apt packages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
OpContext
|
Execution context for the operation. |
required |
wait_for_lock
|
bool | int
|
Wait for the apt lock instead of
failing instantly; |
False
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Yields:
| Name | Type | Description |
|---|---|---|
Command |
AsyncGenerator[Command]
|
Generated apt upgrade commands. |
Raises:
CommandNotFoundError, HostConnectionError
Examples:
Examples can be found in examples/modules/apt/apt_upgrade.py.