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.
This commit is contained in:
Christian Kellner 2021-11-16 16:45:56 +00:00 committed by Alexander Larsson
parent ffdbdf6235
commit 22e670050f

View file

@ -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", [])