From: Michael Tremer Date: Sun, 3 Nov 2024 14:10:58 +0000 (+0000) Subject: backend: Launch Pakfire with its own context X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3569c427743bcabb8dfdc46702b26b07094ba6d8;p=pbs.git backend: Launch Pakfire with its own context Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/__init__.py b/src/buildservice/__init__.py index b9efad0a..fc5a809e 100644 --- a/src/buildservice/__init__.py +++ b/src/buildservice/__init__.py @@ -48,9 +48,6 @@ from .__version__ import VERSION as __version__ from .decorators import * from .constants import * -# Set the cache path -pakfire.set_cache_path("/pub/pakfire/.cache") - class Backend(object): version = __version__ diff --git a/src/buildservice/config.py b/src/buildservice/config.py index 664e1646..6f010ec9 100644 --- a/src/buildservice/config.py +++ b/src/buildservice/config.py @@ -59,17 +59,6 @@ class PakfireConfig(base.Object): return buffer.getvalue() - def _log(self, level, message): - # Remove any trailing newline (but only one) - if message: - message = message.removesuffix("\n") - - # Log to the logger if configured - if self.logger: - return self.logger(level, message) - - return log.log(level, message) - # Repositories def add_repo(self, repo): @@ -84,6 +73,16 @@ class PakfireConfig(base.Object): # Context async def __aenter__(self): + # Setup a new context + ctx = pakfire.Ctx() + + # Set the cache path + #ctx.cache_path = "/pub/pakfire/.cache" + + # Configure the logger + if self.logger: + ctx.set_logger(self.logger) + f = io.StringIO() # Make configuration @@ -97,7 +96,7 @@ class PakfireConfig(base.Object): # Launch a new Pakfire instance (in a separate thread) async with self.backend.tempdir() as d: - return await asyncio.to_thread(pakfire.Pakfire, path=d, arch=self.arch, conf=f) + return await asyncio.to_thread(pakfire.Pakfire, ctx=ctx, path=d, arch=self.arch, conf=f) async def __aexit__(self, type, value, traceback): pass @@ -168,14 +167,14 @@ class PakfireLogger(object): # Register the queue with the logger self.log.addHandler(handler) - def __call__(self, *args, **kwargs): - """ - Logs a message - """ - return self.log.log(*args, **kwargs) - def __str__(self): """ Returns the entire log as a string """ return "\n".join((record.getMessage() for record in self.queue)) + + def log(self, *args, **kwargs): + """ + Logs a message + """ + return self.log.log(*args, **kwargs)