import asyncio
import functools
+import glob
import json
import logging
import logging.handlers
# Setup build logger
logger = BuildLogger(self.log, self.job)
- # Run the build
- try:
- build = self._build(pkg, arch=arch,
- logger=logger._log, build_id=job_id)
-
- # Wait until the build process is done and stream the log in the meantime
- while not build.done():
- await logger.stream(timeout=1)
-
- # Catch any other Exception
- except Exception as e:
- raise e
+ # Create a temporary directory in which the built packages will be copied
+ with tempfile.TemporaryDirectory(prefix="pakfire-packages-") as target:
+ packages = None
- # The build has finished successfully
- else:
- success = True
-
- # Notify the hub that the job has finished
- finally:
- await self.hub.finish_job(
- job_id,
- success=success,
- log=logger.logfile.name,
- )
+ # Run the build
+ try:
+ build = self._build(pkg, arch=arch, target=target,
+ logger=logger._log, build_id=job_id)
+
+ # Wait until the build process is done and stream the log in the meantime
+ while not build.done():
+ await logger.stream(timeout=1)
+
+ # Catch any other Exception
+ except Exception as e:
+ raise e
+
+ # The build has finished successfully
+ else:
+ success = True
+
+ # Find any packages
+ packages = glob.glob("%s/*.pfm" % target)
+
+ # Notify the hub that the job has finished
+ finally:
+ await self.hub.finish_job(
+ job_id,
+ success=success,
+ log=logger.logfile.name,
+ packages=packages,
+ )
def _build(self, pkg, arch=None, logger=None, **kwargs):
"""
async def delete_upload(self, upload_id):
await self._request("DELETE", "/uploads", id=upload_id)
+ async def upload_multi(self, *paths, show_progress=True):
+ """
+ Upload multiple files
+
+ If one file could not be uploaded, any other uploads will be deleted
+ """
+ uploads = []
+
+ # Upload everything
+ try:
+ for path in paths:
+ upload = await self.upload(path, show_progress=show_progress)
+
+ # Store the upload ID
+ uploads.append(upload)
+
+ except Exception as e:
+ # Remove any previous uploads
+ await asyncio.gather(
+ *(self.delete_upload(upload) for upload in uploads),
+ )
+
+ # Raise the exception
+ raise e
+
+ # Return the IDs of the uploads
+ return uploads
+
@staticmethod
def _stream_file(path, size, p, write):
# Start the progressbar
# Return a Job proxy
return Job(self, id, conn)
- async def finish_job(self, job_id, success, log):
+ async def finish_job(self, job_id, success, packages=None, log=None):
"""
Will tell the hub that a job has finished
"""
if log:
log = await self.upload(log, filename="%s.log" % job_id)
+ # Upload the packages
+ if packages:
+ packages = await self.upload_multi(*packages)
+
# Send the request
response = await self._request("POST", "/jobs/%s/finished" % job_id,
- success=success, log=log)
+ success=success, log=log, packages=packages)
# Handle the response
# XXX TODO