From 1d53916a90a9408283d864ce38a2077edaac0600 Mon Sep 17 00:00:00 2001 From: Morten Linderud Date: Mon, 15 Aug 2022 14:39:02 +0200 Subject: [PATCH] mkosi/manifest: Implement support for pacman packages Signed-off-by: Morten Linderud --- mkosi/manifest.py | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/mkosi/manifest.py b/mkosi/manifest.py index 0892266df..945e68530 100644 --- a/mkosi/manifest.py +++ b/mkosi/manifest.py @@ -6,7 +6,7 @@ from datetime import datetime from pathlib import Path from subprocess import DEVNULL, PIPE from textwrap import dedent -from typing import IO, Any, Dict, List, Optional, cast +from typing import IO, Any, Dict, List, Optional, Tuple, cast from .backend import ( Distribution, @@ -65,6 +65,23 @@ class SourcePackageManifest: return t +def parse_pkg_desc(f: Path) -> Tuple[str, str, str, str]: + name = version = base = arch = "" + with f.open() as desc: + for line in desc: + line = line.strip() + if line == "%NAME%": + name = next(desc).strip() + elif line == "%VERSION%": + version = next(desc).strip() + elif line == "%BASE%": + base = next(desc).strip() + elif line == "%ARCH%": + arch = next(desc).strip() + break + return name, version, base, arch + + @dataclasses.dataclass class Manifest: args: MkosiArgs @@ -81,6 +98,8 @@ class Manifest: self.record_rpm_packages(root) if cast(Any, self.args.distribution).package_type == PackageType.deb: self.record_deb_packages(root) + if cast(Any, self.args.distribution).package_type == PackageType.pkg: + self.record_pkg_packages(root) # TODO: add implementations for other package managers def record_rpm_packages(self, root: Path) -> None: @@ -197,6 +216,20 @@ class Manifest: source_package.add(package) + def record_pkg_packages(self, root: Path) -> None: + packages = sorted(root.joinpath("var/lib/pacman/local").glob("*/desc")) + + for desc in packages: + name, version, source, arch = parse_pkg_desc(desc) + package = PackageManifest("pkg", name, version, arch, 0) + self.packages.append(package) + + source_package = self.source_packages.get(source) + if source_package is None: + source_package = SourcePackageManifest(source, None) + self.source_packages[source] = source_package + source_package.add(package) + def has_data(self) -> bool: # We might add more data in the future return len(self.packages) > 0 -- 2.47.2