feat: release v2.0.0 with tab completion, package filtering, db health checks, flatpak and logrotate
Build and Publish Release / Build Packages and Publish (push) Successful in 27s

This commit is contained in:
soda64 committed 2026-10-03 08:31:00 +02:00
1 parent 8d4157b42d
commit 8bec4ed932
27 files changed
+1053 -69

No files matched your search

+49 -10
View File
@@ -1,6 +1,6 @@
import re
from pathlib import Path
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Tuple
from linux_updater.core.runner import CommandRunner
from linux_updater.managers.base import PackageManager
@@ -27,39 +27,67 @@ class AptManager(PackageManager):
cmd = ["apt-get", "update"]
return self.runner.run(cmd, env=self._env(True))
def check_updates(self) -> List[PackageUpdate]:
def check_updates(
self,
exclude: Optional[List[str]] = None,
security_only: bool = False,
) -> List[PackageUpdate]:
cmd = ["apt-get", "-s", "upgrade"]
res = self.runner.run(cmd, env=self._env(True))
updates: List[PackageUpdate] = []
# Inst libssl3 [3.0.13-0ubuntu3.1] (3.0.13-0ubuntu3.4 Ubuntu:24.04/noble-updates [amd64])
import fnmatch
pattern = re.compile(r"^Inst\s+(\S+)\s+\[([^\]]+)\]\s+\((\S+)\s+([^)]*)\)")
pattern_new = re.compile(r"^Inst\s+(\S+)\s+\((\S+)\s+([^)]*)\)")
for line in res.stdout.splitlines():
line = line.strip()
pkg = None
old_ver = "none"
new_ver = ""
repo = None
match = pattern.match(line)
if match:
pkg, old_ver, new_ver, repo = match.groups()
else:
match_new = pattern_new.match(line)
if match_new:
pkg, new_ver, repo = match_new.groups()
if pkg:
if exclude and any(fnmatch.fnmatch(pkg, pat) for pat in exclude):
continue
if security_only:
repo_str = repo.lower() if repo else ""
if "security" not in repo_str and "-sec" not in repo_str:
continue
updates.append(PackageUpdate(package=pkg, current_version=old_ver, new_version=new_ver, repo=repo))
continue
match_new = pattern_new.match(line)
if match_new:
pkg, new_ver, repo = match_new.groups()
updates.append(PackageUpdate(package=pkg, current_version="none", new_version=new_ver, repo=repo))
return updates
def apply_updates(
self,
packages: Optional[List[str]] = None,
exclude: Optional[List[str]] = None,
security_only: bool = False,
dry_run: bool = False,
non_interactive: bool = False,
) -> CommandResult:
cmd = ["apt-get"]
if packages:
cmd.extend(["install", "--only-upgrade", "-y"])
cmd.extend(packages)
import fnmatch
target_pkgs = [p for p in packages if not (exclude and any(fnmatch.fnmatch(p, pat) for pat in exclude))]
if not target_pkgs:
return CommandResult(0, "All specified packages were excluded.", "", True)
cmd.extend(["install", "--only-upgrade", "-y"] + target_pkgs)
elif exclude or security_only:
filtered = self.check_updates(exclude=exclude, security_only=security_only)
if not filtered:
return CommandResult(0, "No matching packages to upgrade after applying filters.", "", True)
target_pkgs = [u.package for u in filtered]
cmd.extend(["install", "--only-upgrade", "-y"] + target_pkgs)
else:
cmd.extend(["upgrade", "-y"])
@@ -127,3 +155,14 @@ class AptManager(PackageManager):
Path("/var/lib/dpkg/lock"),
Path("/var/lib/apt/lists/lock"),
]
def verify_db_consistency(self) -> "Tuple[bool, str]":
audit_res = self.runner.run(["dpkg", "--audit"])
if audit_res.return_code != 0 or audit_res.stdout.strip():
msg = audit_res.stdout.strip() or audit_res.stderr.strip() or "Unconfigured or broken packages detected"
return False, f"dpkg audit found package database issues: {msg[:100]}"
return True, "dpkg package database is consistent."
def repair_db(self) -> CommandResult:
self.runner.run(["dpkg", "--configure", "-a"], env=self._env(True))
return self.runner.run(["apt-get", "install", "-f", "-y"], env=self._env(True))
+16 -2
View File
@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod
from pathlib import Path
from typing import List, Optional
from typing import List, Optional, Tuple
from linux_updater.models import PackageUpdate, CommandResult, RebootStatus
@@ -17,7 +17,11 @@ class PackageManager(ABC):
pass
@abstractmethod
def check_updates(self) -> List[PackageUpdate]:
def check_updates(
self,
exclude: Optional[List[str]] = None,
security_only: bool = False,
) -> List[PackageUpdate]:
"""Lists available package updates."""
pass
@@ -25,6 +29,8 @@ class PackageManager(ABC):
def apply_updates(
self,
packages: Optional[List[str]] = None,
exclude: Optional[List[str]] = None,
security_only: bool = False,
dry_run: bool = False,
non_interactive: bool = False,
) -> CommandResult:
@@ -60,3 +66,11 @@ class PackageManager(ABC):
def get_lock_files(self) -> List[Path]:
"""Returns paths of lockfiles used by this manager."""
pass
def verify_db_consistency(self) -> "Tuple[bool, str]":
"""Checks whether the package manager database has broken/interrupted transactions."""
return True, "Package database is consistent."
def repair_db(self) -> CommandResult:
"""Attempts automated repair of interrupted/broken package transactions."""
return CommandResult(0, "No repair needed.", "", True)
+29 -1
View File
@@ -29,8 +29,17 @@ class DnfManager(PackageManager):
cmd = [self.binary, "makecache"]
return self.runner.run(cmd)
def check_updates(self) -> List[PackageUpdate]:
def check_updates(
self,
exclude: Optional[List[str]] = None,
security_only: bool = False,
) -> List[PackageUpdate]:
cmd = [self.binary, "check-update"]
if security_only:
cmd.append("--security")
if exclude:
for pat in exclude:
cmd.extend(["-x", pat])
res = self.runner.run(cmd)
# DNF returns exit code 100 when updates are found, 0 when clean
@@ -56,6 +65,8 @@ class DnfManager(PackageManager):
def apply_updates(
self,
packages: Optional[List[str]] = None,
exclude: Optional[List[str]] = None,
security_only: bool = False,
dry_run: bool = False,
non_interactive: bool = False,
) -> CommandResult:
@@ -65,6 +76,13 @@ class DnfManager(PackageManager):
else:
cmd.append("-y")
if security_only:
cmd.append("--security")
if exclude:
for pat in exclude:
cmd.extend(["-x", pat])
if packages:
cmd.extend(packages)
@@ -412,3 +430,13 @@ class DnfManager(PackageManager):
Path("/var/lib/rpm/.rpm.lock"),
Path("/var/run/dnf.pid"),
]
def verify_db_consistency(self) -> Tuple[bool, str]:
check_res = self.runner.run([self.binary, "check"])
if check_res.return_code != 0:
msg = check_res.stderr.strip() or check_res.stdout.strip() or "Transaction database issues found"
return False, f"dnf check found package database issues: {msg[:100]}"
return True, "RPM database is consistent."
def repair_db(self) -> CommandResult:
return self.runner.run([self.binary, "clean", "all"])
+37 -4
View File
@@ -1,7 +1,7 @@
import os
import shutil
from pathlib import Path
from typing import List, Optional
from typing import List, Optional, Tuple
from linux_updater.core.runner import CommandRunner
from linux_updater.managers.base import PackageManager
@@ -19,24 +19,32 @@ class PacmanManager(PackageManager):
def refresh_repositories(self) -> CommandResult:
return self.runner.run(["pacman", "-Sy"])
def check_updates(self) -> List[PackageUpdate]:
def check_updates(
self,
exclude: Optional[List[str]] = None,
security_only: bool = False,
) -> List[PackageUpdate]:
# Prefer checkupdates if installed (safe non-root update check)
cmd = ["checkupdates"] if shutil.which("checkupdates") else ["pacman", "-Qu"]
res = self.runner.run(cmd)
import fnmatch
updates: List[PackageUpdate] = []
for line in res.stdout.splitlines():
line = line.strip()
if not line or "->" not in line:
continue
# Format: package old_version -> new_version [repo]
try:
left, right = line.split("->", 1)
left_parts = left.strip().split()
right_parts = right.strip().split()
pkg = left_parts[0]
if exclude and any(fnmatch.fnmatch(pkg, pat) for pat in exclude):
continue
old_ver = left_parts[1] if len(left_parts) > 1 else "unknown"
new_ver = right_parts[0] if right_parts else "unknown"
repo = right_parts[1].strip("[]") if len(right_parts) > 1 else None
@@ -50,22 +58,32 @@ class PacmanManager(PackageManager):
def apply_updates(
self,
packages: Optional[List[str]] = None,
exclude: Optional[List[str]] = None,
security_only: bool = False,
dry_run: bool = False,
non_interactive: bool = False,
) -> CommandResult:
if packages:
import fnmatch
target_pkgs = [p for p in packages if not (exclude and any(fnmatch.fnmatch(p, pat) for pat in exclude))]
if not target_pkgs:
return CommandResult(0, "All specified packages were excluded.", "", True)
cmd = ["pacman", "-S"]
if dry_run:
cmd.append("-p")
else:
cmd.append("--noconfirm")
cmd.extend(packages)
if exclude:
cmd.extend(["--ignore", ",".join(exclude)])
cmd.extend(target_pkgs)
else:
cmd = ["pacman", "-Su"]
if dry_run:
cmd.append("-p")
else:
cmd.append("--noconfirm")
if exclude:
cmd.extend(["--ignore", ",".join(exclude)])
return self.runner.run(cmd, stream=not dry_run)
@@ -112,3 +130,18 @@ class PacmanManager(PackageManager):
def get_lock_files(self) -> List[Path]:
return [Path("/var/lib/pacman/db.lck")]
def verify_db_consistency(self) -> "Tuple[bool, str]":
lock_p = Path("/var/lib/pacman/db.lck")
if lock_p.exists():
return False, f"Stale pacman database lock: {lock_p}"
return True, "Pacman database is consistent."
def repair_db(self) -> CommandResult:
lock_p = Path("/var/lib/pacman/db.lck")
if lock_p.exists():
try:
lock_p.unlink()
except Exception:
pass
return CommandResult(0, "Pacman database checked.", "", True)