feat(inspector): implement slice 2 comprehensive host state inspector
This commit is contained in:
1 parent
2602b66a90
commit
66ca179937
11 files changed
+777
-25
No files matched your search
@@ -0,0 +1,38 @@
|
||||
"""RPM package manager adapter (RHEL, AlmaLinux, Rocky, CentOS, Fedora)."""
|
||||
|
||||
import subprocess
|
||||
from typing import List
|
||||
|
||||
from linux_backuper.models import PackageItem
|
||||
from linux_backuper.managers.base import BasePackageManager
|
||||
|
||||
class RpmPackageManager(BasePackageManager):
|
||||
"""Inspector for RPM-based Linux distributions."""
|
||||
|
||||
def get_manager_name(self) -> str:
|
||||
return "rpm"
|
||||
|
||||
def list_packages(self) -> List[PackageItem]:
|
||||
"""List installed packages via rpm query."""
|
||||
cmd = ["rpm", "-qa", "--qf", "%{NAME}|%{VERSION}-%{RELEASE}|%{ARCH}\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 or line.startswith("("):
|
||||
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
|
||||
Reference in new issue
Block a user