debian-forge/osbuild/solver/__init__.py
Michael Vogt d068c6d91f dnfjson: detect/error if no repositories are defined
This commit adds an error message if no repositories are
defined in the dnfjson query. We had the issue in
https://github.com/osbuild/bootc-image-builder/issues/922
that in a RHEL bootc-container no repositories are defined.

Here the error is quite confusing, as it complains about
error marking packages which is technically correct but
hides the root of the problem.

With this detect we can construct a more useful error
message in the higher layers.
2025-05-12 20:51:57 +02:00

86 lines
1.9 KiB
Python
Executable file

import abc
import os
import urllib.error
import urllib.parse
import urllib.request
class Solver(abc.ABC):
@abc.abstractmethod
def dump(self):
pass
@abc.abstractmethod
def depsolve(self, arguments):
pass
@abc.abstractmethod
def search(self, args):
pass
class SolverBase(Solver):
# put any shared helpers in here
pass
class SolverException(Exception):
pass
class GPGKeyReadError(SolverException):
pass
class TransactionError(SolverException):
pass
class RepoError(SolverException):
pass
class NoReposError(SolverException):
pass
class MarkingError(SolverException):
pass
class DepsolveError(SolverException):
pass
class InvalidRequestError(SolverException):
pass
def modify_rootdir_path(path, root_dir):
if path and root_dir:
# if the root_dir is set, we need to translate the key path to be under this directory
return os.path.join(root_dir, path.lstrip("/"))
return path
def read_keys(paths, root_dir=None):
keys = []
for path in paths:
url = urllib.parse.urlparse(path)
if url.scheme == "file":
path = url.path
path = modify_rootdir_path(path, root_dir)
try:
with open(path, mode="r", encoding="utf-8") as keyfile:
keys.append(keyfile.read())
except Exception as e:
raise GPGKeyReadError(f"error loading gpg key from {path}: {e}") from e
elif url.scheme in ["http", "https"]:
try:
resp = urllib.request.urlopen(urllib.request.Request(path))
keys.append(resp.read().decode())
except urllib.error.URLError as e:
raise GPGKeyReadError(f"error reading remote gpg key at {path}: {e}") from e
else:
raise GPGKeyReadError(f"unknown url scheme for gpg key: {url.scheme} ({path})")
return keys