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:
parent
ffdbdf6235
commit
22e670050f
1 changed files with 6 additions and 4 deletions
|
|
@ -617,14 +617,16 @@ class ManifestFile:
|
||||||
raise ValueError(f"Incompatible manifest version {m.version}")
|
raise ValueError(f"Incompatible manifest version {m.version}")
|
||||||
return m
|
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:
|
for p in [self.basedir] + dirs:
|
||||||
with contextlib.suppress(FileNotFoundError):
|
with contextlib.suppress(FileNotFoundError):
|
||||||
fullpath = os.path.join(p, path)
|
fullpath = os.path.join(p, path)
|
||||||
with open(fullpath, "r") as f:
|
return open(fullpath, mode)
|
||||||
return ManifestFile.load_from_fd(f, path, self.overrides, self.vars)
|
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):
|
def depsolve(self, solver: DepSolver, desc: Dict):
|
||||||
repos = desc.get("repos", [])
|
repos = desc.get("repos", [])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue