]> git.ipfire.org Git - pbs.git/commitdiff
config: Make it easier to generate a text configuration
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Jan 2025 13:54:39 +0000 (13:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 26 Jan 2025 13:54:39 +0000 (13:54 +0000)
We cannot use the old method any more since we need to call async
methods.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/config.py

index cc31c1f9af66fdd2b8a9ae0e95283e49da76b473..486fd5a1d231d9b3427ee89f49debce375cdd31c 100644 (file)
@@ -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):