duck.cli.commands.sync.platform_utils

Detects the current operating system and the package manager it favors.

Module Contents

Functions

detect_backend_name

Picks the best matching system package manager for this machine.

detect_os_family

Classifies the host machine into a coarse OS family.

is_root

Checks whether the current process is already running as root.

is_termux

Checks whether Duck Sync is running inside Termux on Android.

read_linux_distro_id

Reads the distro id from /etc/os-release.

Data

LINUX_BACKEND_PRIORITY

API

duck.cli.commands.sync.platform_utils.LINUX_BACKEND_PRIORITY

[‘apt’, ‘dnf’, ‘pacman’, ‘zypper’, ‘apk’]

duck.cli.commands.sync.platform_utils.detect_backend_name() str[source]

Picks the best matching system package manager for this machine.

Returns:

A backend identifier such as “apt”, “brew”, “dnf”, “pacman”, “choco”, or “termux” that backends.get_backend understands.

Raises:

UnsupportedPlatformError – If no known package manager is found.

duck.cli.commands.sync.platform_utils.detect_os_family(raise_for_unknown: bool = True) str[source]

Classifies the host machine into a coarse OS family.

Returns:

One of “linux”, “macos”, “windows”.

Raises:

UnsupportedPlatformError – If the platform cannot be classified (only is raise_for_uknown=True).

duck.cli.commands.sync.platform_utils.is_root() bool[source]

Checks whether the current process is already running as root.

Used to skip prefixing install commands with sudo, since sudo is unavailable or unnecessary inside most containers that already run as root.

Returns:

True on POSIX systems running as uid 0. Always False on Windows, since sudo does not apply there.

duck.cli.commands.sync.platform_utils.is_termux() bool[source]

Checks whether Duck Sync is running inside Termux on Android.

Termux reports itself as a normal Linux uname, so it needs its own check rather than falling through the generic Linux package manager detection. It also has no root and no sudo binary.

Returns:

True when the Termux environment and pkg command are both present.

duck.cli.commands.sync.platform_utils.read_linux_distro_id() str[source]

Reads the distro id from /etc/os-release.

Returns:

The lowercase distro id (e.g. “ubuntu”, “fedora”), or an empty string when the file is unavailable.