feat(inspector): implement slice 2 comprehensive host state inspector

This commit is contained in:
soda64 committed 2026-10-09 18:48:51 +02:00
1 parent 2602b66a90
commit 66ca179937
11 files changed
+777 -25

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
"""DPKG package manager adapter (Debian, Ubuntu)."""
import subprocess
from typing import List
from linux_backuper.models import PackageItem
from linux_backuper.managers.base import BasePackageManager
class DpkgPackageManager(BasePackageManager):
"""Inspector for DPKG-based Linux distributions."""
def get_manager_name(self) -> str:
return "dpkg-query"
def list_packages(self) -> List[PackageItem]:
"""List installed packages via dpkg-query."""
cmd = ["dpkg-query", "-W", "-f=${Package}|${Version}|${Architecture}\n"]
try:
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=False)
if res.returncode != 0:
return []
except (OSError, FileNotFoundError):
return []
packages: List[PackageItem] = []
for line in res.stdout.splitlines():
line = line.strip()
if not line:
continue
parts = line.split("|")
if len(parts) >= 2:
name = parts[0]
version = parts[1]
arch = parts[2] if len(parts) > 2 else ""
packages.append(PackageItem(name=name, version=version, arch=arch))
packages.sort(key=lambda p: p.name)
return packages