From: Michael Tremer Date: Fri, 27 May 2022 13:41:00 +0000 (+0000) Subject: daemon: Add some basic steps to build a package X-Git-Tag: 0.9.28~721 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f0cd2752d373aa454292099a9638a16bb728eb0;p=pakfire.git daemon: Add some basic steps to build a package Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/daemon.py b/src/pakfire/daemon.py index 39277a796..dab977c0b 100644 --- a/src/pakfire/daemon.py +++ b/src/pakfire/daemon.py @@ -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