From: Michael Tremer Date: Sun, 26 Jan 2025 13:54:39 +0000 (+0000) Subject: config: Make it easier to generate a text configuration X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b4ae30b9202c5cbbb667dcce52a868ceec5dc46e;p=pbs.git config: Make it easier to generate a text configuration We cannot use the old method any more since we need to call async methods. Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/config.py b/src/buildservice/config.py index cc31c1f9..486fd5a1 100644 --- a/src/buildservice/config.py +++ b/src/buildservice/config.py @@ -38,17 +38,6 @@ class PakfireConfig(base.Object): # Log messages to here self.logger = logger - def __str__(self): - config = self._make_config() - - return self._to_string(config) - - def _to_string(self, config): - buffer = io.StringIO() - config.write(buffer) - - return buffer.getvalue() - # Repositories async def fetch_repos(self): @@ -80,25 +69,19 @@ class PakfireConfig(base.Object): if self.logger: ctx.set_logger(self.logger) - f = io.StringIO() - # Make configuration - config = await self._make_config(local=True) + config = await self.config(local=True) - # Write the configuration to the buffer - config.write(f) - f.seek(0) - - log.debug("Launching Pakfire with configuration:\n%s", f.getvalue()) + log.debug("Launching Pakfire with configuration:\n%s", config.getvalue()) # Launch a new Pakfire instance (in a separate thread) async with self.backend.tempdir() as d: - return await asyncio.to_thread(pakfire.Pakfire, ctx=ctx, path=d, arch=self.arch, conf=f) + return await asyncio.to_thread(pakfire.Pakfire, ctx=ctx, path=d, arch=self.arch, conf=config) async def __aexit__(self, type, value, traceback): pass - async def _make_config(self, local=False): + async def config(self, local=False): """ Generates the configuration file """ @@ -124,7 +107,14 @@ class PakfireConfig(base.Object): repo.write_config(config, local=local, include_source=self.include_source, mirrored=self.mirrored, build=self.build) - return config + # Allocate a buffer and write the configuration to it + f = io.StringIO() + config.write(f) + + # Rewind the buffer + f.seek(0) + + return f class PakfireLogger(object):