import urllib.parse
from . import base
+from . import config
from . import database
from .decorators import *
log.info("Creating build for %s from %s" % (self, build))
try:
- # Create a new repository
- repo = await self.backend.repos.create(
- self.monitoring.distro, "Test Build for %s" % self, owner=owner)
-
# Create a new temporary space for the
async with self.backend.tempdir() as target:
# Create a new source package
file = await self._update_source_package(build.pkg, target)
- # Upload the file
- upload = await self.backend.uploads.create_from_local(file)
+ if file:
+ # Create a new repository
+ repo = await self.backend.repos.create(
+ self.monitoring.distro, "Test Build for %s" % self, owner=owner)
- try:
- # Create a package
- package = await self.backend.packages.create(upload)
+ # Upload the file
+ upload = await self.backend.uploads.create_from_local(file)
+
+ try:
+ # Create a package
+ package = await self.backend.packages.create(upload)
- # Create the build
- build = await self.backend.builds.create(repo, package, owner=owner)
+ # Create the build
+ build = await self.backend.builds.create(repo, package, owner=owner)
- finally:
- await upload.delete()
+ finally:
+ await upload.delete()
# If anything went wrong, then remove the repository
except Exception as e:
if not package.is_source():
raise RuntimeError("%s is not a source package" % package)
+ # Capture Pakfire's log
+ logger = config.PakfireLogger()
+
# Create temporary directory to extract the package to
- async with self.backend.tempdir() as tmp:
- # Path to downloaded files
- files = os.path.join(tmp, "files")
+ try:
+ async with self.backend.tempdir() as tmp:
+ # Path to downloaded files
+ files = os.path.join(tmp, "files")
- # Path to the makefile
- makefile = os.path.join(tmp, "%s.nm" % package.name)
+ # Path to the makefile
+ makefile = os.path.join(tmp, "%s.nm" % package.name)
- # Create a Pakfire instance from this distribution
- async with self.monitoring.distro.pakfire() as p:
- # Open the archive
- archive = await asyncio.to_thread(p.open, package.path)
+ # Create a Pakfire instance from this distribution
+ async with self.monitoring.distro.pakfire(logger=logger) as p:
+ # Open the archive
+ archive = await asyncio.to_thread(p.open, package.path)
- # Extract the archive into the temporary space
- await asyncio.to_thread(archive.extract, path=tmp)
+ # Extract the archive into the temporary space
+ await asyncio.to_thread(archive.extract, path=tmp)
- # XXX directories are being created with the wrong permissions
- os.system("chmod a+x -R %s" % tmp)
+ # XXX directories are being created with the wrong permissions
+ os.system("chmod a+x -R %s" % tmp)
- # Remove any downloaded files
- await asyncio.to_thread(shutil.rmtree, files)
+ # Remove any downloaded files
+ await asyncio.to_thread(shutil.rmtree, files)
- # Update the makefile
- diff = await self._update_makefile(makefile)
+ # Update the makefile
+ diff = await self._update_makefile(makefile)
- # Log the diff
- log.info("Generated diff:\n%s" % diff)
+ # Log the diff
+ log.info("Generated diff:\n%s" % diff)
+
+ # Store the diff
+ self._set_attribute("diff", diff)
+
+ # Generate a new source package
+ return await asyncio.to_thread(p.dist, makefile, target)
+
+ # If we could not create a new source package, this is okay and we will continue
+ # without. However, we will log the exception...
+ except Exception as e:
+ log.error("Could not create source package for %s" % self, exc_info=True)
- # Store the diff
- self._set_attribute("diff", diff)
+ return None
- # Generate a new source package
- return await asyncio.to_thread(p.dist, makefile, target)
+ # Store the Pakfire log
+ finally:
+ self._set_attribute("log", "%s" % logger)
async def _update_makefile(self, path):
"""