This should help us to block less when initializing a Pakfire instance.
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
"""
Opens a package and returns the archive
"""
- return await asyncio.to_thread(self._open, path)
-
- def _open(self, path):
log.debug("Opening %s..." % path)
# Open the archive
- with self.pakfire() as p:
- return p.open(path)
+ async with self.pakfire() as p:
+ return await asyncio.to_thread(p.open, path)
@property
def ssl_context(self):
#!/usr/bin/python3
+import asyncio
import configparser
import io
import logging
import pakfire
-import tempfile
from . import base
# Context
- def __enter__(self):
+ async def __aenter__(self):
# Make configuration
config = self._make_config(local=True)
log.debug("Launching Pakfire with configuration:\n%s", self._to_string(config))
- with tempfile.NamedTemporaryFile(mode="w+") as t:
+ async with self.backend.tempfile(mode="w+") as t:
# Write the configuration to disk
config.write(t)
t.flush()
- # Launch a new Pakfire instance
- return pakfire.Pakfire(arch=self.arch, conf=t.name,
+ # Launch a new Pakfire instance (in a separate thread)
+ p = await asyncio.to_thread(pakfire.Pakfire, arch=self.arch, conf=t.name,
logger=self._log, offline=False)
- def __exit__(self, type, value, traceback):
+ return p
+
+ async def __aexit__(self, type, value, traceback):
pass
def _make_config(self, local=False):
packages = []
- with self.pakfire(include_source=True) as p:
+ async with self.pakfire(include_source=True) as p:
for package in self.packages:
for pkg in p.whatprovides("%s = %s" % (package.name, package.evr)):
# XXX we should search straight away for the UUID here,
Creates a new key
"""
# Launch a new Pakfire instance
- with self.backend.pakfire() as p:
+ async with self.backend.pakfire() as p:
# Generate the new key
key = p.generate_key(DEFAULT_ALGORITHM, comment)
makefile = os.path.join(tmp, "%s.nm" % package.name)
# Create a Pakfire instance from this distribution
- with self.monitoring.distro.pakfire() as p:
+ async with self.monitoring.distro.pakfire() as p:
# Open the archive
archive = await asyncio.to_thread(p.open, package.path)
# Pakfire instances at a time which leads to Pakfire only being initialized once
# per architecture. We are then able to run all dependency checks one after the
# other.
- with contextlib.ExitStack() as stack:
+ async with contextlib.AsyncExitStack() as stack:
ps = {}
success = False
try:
p = ps[job.arch]
except KeyError:
- p = ps[job.arch] = stack.enter_context(
+ p = ps[job.arch] = await stack.enter_async_context(
self.pakfire(arch=job.arch)
)
# Create a new pakfire instance
async with self.backend.tempdir(prefix="pakfire-repo-") as t:
- with self.pakfire() as p:
+ async with self.pakfire() as p:
# Fetch the key
if self.key:
key = self.key._make_key(p)
makefile = os.path.join(path, "%s/%s.nm" % (self.name, self.name))
# Launch a Pakfire instance with the repository configuration
- with self.source.repo.pakfire() as p:
+ async with self.source.repo.pakfire() as p:
log.debug("Running dist for %s..." % makefile)
# Run dist() in a separate thread
import test
class SetupTestCase(test.TestCase):
- def test_pakfire(self):
+ async def test_pakfire(self):
"""
This test checks whether we can launch into a local Pakfire instance
"""
- with self.backend.pakfire() as p:
+ async with self.backend.pakfire() as p:
pass
async def test_unlink(self):