From 22e670050f9af6af9caef9ddeea9b4ab17c6d8d1 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 16 Nov 2021 16:45:56 +0000 Subject: [PATCH] osbuild-mpp: extract finding files and opening Extract the code that finds a file and opens it from the existing method that find manifests and opens them. This is so that the former code can be re-used. --- tools/osbuild-mpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/osbuild-mpp b/tools/osbuild-mpp index e226c3f0..8660581a 100755 --- a/tools/osbuild-mpp +++ b/tools/osbuild-mpp @@ -617,14 +617,16 @@ class ManifestFile: raise ValueError(f"Incompatible manifest version {m.version}") return m - def find_and_load_manifest(self, path, dirs): + def find_and_open_file(self, path, dirs, mode="r"): for p in [self.basedir] + dirs: with contextlib.suppress(FileNotFoundError): fullpath = os.path.join(p, path) - with open(fullpath, "r") as f: - return ManifestFile.load_from_fd(f, path, self.overrides, self.vars) + return open(fullpath, mode) + raise FileNotFoundError(f"Could not find file '{path}'") - raise FileNotFoundError(f"Could not find manifest '{path}'") + def find_and_load_manifest(self, path, dirs): + with self.find_and_open_file(path, dirs) as f: + return ManifestFile.load_from_fd(f, path, self.overrides, self.vars) def depsolve(self, solver: DepSolver, desc: Dict): repos = desc.get("repos", [])