]> git.ipfire.org Git - pakfire.git/commitdiff
daemon: Add some basic steps to build a package
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 May 2022 13:41:00 +0000 (13:41 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 May 2022 13:41:00 +0000 (13:41 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/daemon.py

index 39277a796af565c5a7d181b9c1c860d5679cf2df..dab977c0b67ac25dfff02326539a732a1713c5bd 100644 (file)
@@ -1,12 +1,14 @@
 #!/usr/bin/python3
 
 import asyncio
+import functools
 import json
 import logging
 import multiprocessing
 import setproctitle
 import signal
 import socket
+import tempfile
 
 from . import _pakfire
 from . import config
@@ -226,9 +228,38 @@ class Worker(multiprocessing.Process):
                # Set the process title
                setproctitle.setproctitle("pakfire-worker job %s" % job_id)
 
-               # XXX Do something for now
-               import time
-               time.sleep(10)
+               # Fetch the build architecture
+               arch = self.data.get("arch")
+
+               # Use the native architecture for noarch
+               if arch == "noarch":
+                       arch = None
+
+               # Fetch the package URL
+               pkg = self.data.get("pkg")
+               if not pkg:
+                       raise ValueError("Did not received a package URL")
+
+               # Setup Pakfire instance
+               try:
+                       p = _pakfire.Pakfire(
+                               conf=self.pakfire_conf,
+                               arch=arch,
+
+                               # Set up logging
+                               #logger=logger.log,
+
+                               # Enable build mode and disable snapshots
+                               build=True,
+                               enable_snapshot=False,
+                               interactive=False,
+                       )
+               finally:
+                       # Delete the configuration file
+                       os.unlink(self.pakfire_conf)
+
+               # Run the build
+               p.build(pkg, build_id=job_id)
 
        def shutdown(self):
                self.log.debug("Shutting down worker %s" % self.pid)
@@ -255,3 +286,19 @@ class Worker(multiprocessing.Process):
                        Handle signal SIGTERM.
                """
                self.shutdown()
+
+       @functools.cached_property
+       def pakfire_conf(self):
+               """
+                       Writes the pakfire configuration to file and returns its path
+               """
+               conf = self.data.get("conf")
+
+               # Write the configuration to file
+               f = tempfile.NamedTemporaryFile(delete=False)
+               if conf:
+                       f.write(conf.encode())
+               f.close()
+
+               # Return the path
+               return f.name