Complete API documentation for all modules in Tuxgrade.
Kernel update detection and management module.
Note: The implementation varies by distribution. Fedora/RHEL use DNF for kernel checks, while Ubuntu/Debian use APT.
Check if a new kernel version is available.
On Fedora/RHEL, queries DNF for kernel package updates using dnf5 check-upgrade -q kernel*.
On Ubuntu/Debian, queries APT for kernel package updates.
Exit code 0 means no updates, 100 means updates available.
Returns:
Trueif a kernel update is available,Falseotherwise.
Raises:
CommandError: If dnf5 fails with an unexpected exit code.
Example:
from core import kernel
if kernel.new_kernel_version():
print("Kernel update available!")Extract the kernel version string from package manager output.
On Fedora/RHEL: Queries DNF for kernel-helper package and extracts the version number (e.g., "6.12.5" from "6.12.5-300.fc41").
On Ubuntu/Debian: No kernel check required.
Returns:
- Kernel version string (e.g., "6.17.12").
Raises:
CommandError: If kernel-helper version cannot be found in the output.
Example:
from core import kernel
version = kernel.get_new_kernel_version()
print(f"New kernel version: {version}")Prompt user to confirm kernel upgrade.
Displays an interactive prompt asking the user to confirm the kernel update. Accepts 'y' or 'Y' for confirmation, exits on any other input.
Args:
new_version: The version string of the new kernel (e.g., "6.12.5").
Returns:
Trueif user confirms with 'y' or 'Y'.
Raises:
SystemExit: If user declines the kernel update or presses Ctrl+C.
Example:
from core import kernel
if kernel.new_kernel_version():
version = kernel.get_new_kernel_version()
kernel.confirm_kernel_update(version)
# Continues only if user confirmedFedora-specific update implementation.
Features:
- DNF/DNF5 detection and usage
- NVIDIA akmods rebuilds
- Fedora-specific kernel handling
Debian-specific update implementation.
Features:
- APT package management
- Debian kernel handling
- apt-specific maintenance tasks
RHEL/CentOS/AlmaLinux/Rocky-specific update implementation.
Features:
- DNF package management
- subscription-manager integration
- RHEL-specific repositories
Arch Linux-specific update implementation.
Features:
- Pacman/Paru/Yay package management
- AUR helper detection
- Arch-specific kernel handling
Fallback for unknown distributions.
Features:
- Basic package manager detection
- Limited functionality
- Graceful degradation
DNF package manager update module (for Fedora/RHEL-based distributions).
Check if DNF is installed on the system.
Returns:
Trueif DNF is available,Falseotherwise.
Update all DNF packages on the system.
Raises:
RuntimeError: If DNF is not installed on the system.
Example:
from package_managers import dnf
dnf.update_dnf()Clean DNF package cache and old metadata.
Removes cached packages and old metadata to save disk space.
Raises:
RuntimeError: If DNF is not installed on the system.
Example:
from package_managers import dnf
dnf.clean_dnf_cache()Details:
dnf5 clean packages- Removes cached package filesdnf5 clean metadata- Removes old metadata
APT package manager update module (for Debian/Ubuntu-based distributions).
Check if APT is installed on the system.
Returns:
Trueif APT is available,Falseotherwise.
Update all APT packages on the system.
Raises:
RuntimeError: If APT is not installed on the system.
Example:
from package_managers import apt
apt.update_apt()Flatpak package manager update module.
Check if Flatpak is installed on the system.
Returns:
Trueif Flatpak is available,Falseotherwise.
Update all installed Flatpak applications.
If Flatpak is not installed, prints a message and returns without error.
Example:
from package_managers import flatpak
flatpak.update_flatpak()Snap package manager update module.
Update all installed Snap applications.
If Snap is not installed, prints a message and returns without error.
Example:
from package_managers import snap
snap.update_snap()Homebrew package manager update module.
Check if Homebrew is installed on the system.
Returns:
Trueif Homebrew is available,Falseotherwise.
Update all Homebrew packages on the system.
Raises:
RuntimeError: If Homebrew is not installed on the system.
Example:
from package_managers import brew
brew.update_brew()Initramfs regeneration module.
Rebuild the initramfs if a new kernel is detected.
Uses dracut to force regeneration of all initramfs images. This is necessary after kernel updates to ensure the new kernel can boot properly.
Args:
new_kernel: True if a new kernel was installed, False otherwise.
Returns:
- A status message indicating whether initramfs was rebuilt or skipped.
Example:
from core import init
message = init.rebuild_initramfs(new_kernel=True)
print(message)NVIDIA kernel module rebuild module.
Rebuild NVIDIA kernel modules using akmods.
If akmods is not installed, returns a message and skips rebuild.
Returns:
- A status message indicating whether NVIDIA modules were rebuilt or skipped.
Example:
from core import nvidia
message = nvidia.rebuild_nvidia_modules()
print(message)Command execution module.
Exception raised when a command execution fails.
Run a shell command with live output.
Args:
cmd: The command to run as a list of strings (e.g.,["ls", "-la"]).check: If True, raises CommandError on non-zero exit codes (default). If False, returns CompletedProcess with any exit code.
Returns:
CompletedProcessinstance with returncode, stdout, and stderr attributes.
Raises:
CommandError: If the command fails (non-zero exit code) and check=True.
Example:
from helper import runner
# Basic usage
result = runner.run(["ls", "-la"])
print(result.stdout)
# With error handling disabled
result = runner.run(["some-command"], check=False)
if result.returncode == 0:
print("Success")
else:
print(f"Failed with code {result.returncode}")Command-line interface utilities module.
Execute a function and display its output.
Args:
function: Callable that performs an operation (no arguments needed).
Example:
from helper import cli_print_utility
from package_managers import dnf
cli_print_utility.print_output(dnf.update_dnf)Print a formatted header with decorative borders.
Displays the given string as a centered header surrounded by hash symbols.
Args:
string: The text to display in the header.
Example:
from helper import cli_print_utility
cli.print_header("Update DNF Packages")
# Outputs:
# #########################
# # Update DNF Packages #
# #########################Sudo privilege persistence module.
For detailed documentation, see sudo_keepalive.md.
Start global sudo keepalive.
Creates and starts a global singleton keepalive instance if it doesn't exist, or starts the existing instance.
Args:
refresh_interval: Seconds between sudo refreshes (default: 60).
Example:
from helper import sudo_keepalive
sudo_keepalive.start()
# Sudo privileges maintainedStop global sudo keepalive.
Stops the global singleton keepalive instance if it exists. Safe to call even if keepalive was never started.
Example:
from helper import sudo_keepalive
sudo_keepalive.stop()Check if global sudo keepalive is running.
Returns:
Trueif the global keepalive is active,Falseotherwise.
Example:
from helper import sudo_keepalive
if sudo_keepalive.is_running():
print("Keepalive is active")All functions use Python type hints. Common types used:
bool: Boolean valuestr: String valueint: Integer valueNone: No return valuelist[str]: List of stringsCompletedProcess: From subprocess module
CommandError: Raised when a shell command failsRuntimeError: Raised when a required tool is missingSystemExit: Raised when user cancels critical operation
from helper import runner
try:
runner.run(["some", "command"])
except runner.CommandError as e:
print(f"Command failed: {e}")from package_managers import flatpak
if flatpak.check_flatpak_installed():
flatpak.update_flatpak()
else:
print("Flatpak not available")from helper import runner
# Method 1: Try-except
try:
runner.run(["command"])
except runner.CommandError:
print("Command failed")
# Method 2: check=False
result = runner.run(["command"], check=False)
if result.returncode != 0:
print("Command failed")