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))