#!/usr/bin/python
+import aiofiles
import asyncio
import configparser
import inspect
"""
Runs this shell command
"""
- with tempfile.TemporaryDirectory() as tmp:
+ async with self.tempdir() as tmp:
# Create a minimal environment
env = {
"HOME" : os.environ.get("HOME", tmp),
"""
path = self.path("tmp")
- return tempfile.NamedTemporaryFile(mode=mode, dir=path, delete=delete)
+ return aiofiles.tempfile.NamedTemporaryFile(mode=mode, dir=path, delete=delete)
def tempdir(self, **kwargs):
"""
# Default to our own tmp directory
path = self.path("tmp")
- return tempfile.TemporaryDirectory(dir=path, **kwargs)
+ return aiofiles.tempfile.TemporaryDirectory(dir=path, **kwargs)
def _write_tempfile(self, content):
"""
import io
import logging
import pakfire
+import tempfile
from . import base
log.debug("Launching Pakfire with configuration:\n%s", self._to_string(config))
- with self.backend.tempfile(mode="w+") as t:
+ with tempfile.NamedTemporaryFile(mode="w+") as t:
# Write the configuration to disk
config.write(t)
t.flush()
import os
import re
import shutil
-import tempfile
import urllib.parse
from . import base
self.monitoring.distro, "Test Build for %s" % self, owner=owner)
# Create a new temporary space for the
- with tempfile.TemporaryDirectory() as target:
+ async with self.backend.tempdir() as target:
# Create a new source package
file = await self._update_source_package(build.pkg, target)
raise RuntimeError("%s is not a source package" % package)
# Create temporary directory to extract the package to
- with tempfile.TemporaryDirectory() as tmp:
+ async with self.backend.tempdir() as tmp:
# Path to downloaded files
files = os.path.join(tmp, "files")
key = None
# Create a new pakfire instance
- with self.backend.tempdir(prefix="pakfire-repo-") as t:
+ async with self.backend.tempdir(prefix="pakfire-repo-") as t:
with self.pakfire() as p:
# Fetch the key
if self.key:
await self.backend.chmod(t, 0o755)
# Perform an atomic replace of the repository directory
- with self.backend.tempdir(prefix="pakfire-repo-") as bin:
+ async with self.backend.tempdir(prefix="pakfire-repo-") as bin:
# Local path
path = self.local_path()
# Move the new repository data to its destination
await self.backend.move(t, path)
- # Remove the temporary directory
- # The block would normally automatically cleanup after itself, but
- # would block. Therefore we are removing the vast majority of the
- # data here so that the blocking operation would be shorter.
- await self.backend.rmtree(bin)
-
# Delete
async def delete(self, user=None):
try:
# Create a new temporary directory and check out the requested revision
- with tempfile.TemporaryDirectory() as path:
+ async with self.backend.tempdir() as path:
await self.source.git.checkout(self.commit.revision, path)
# Create a path for the source packages
""", uuid,
)
- def create(self, filename, size, owner=None):
+ async def create(self, filename, size, owner=None):
builder = None
user = None
user.check_quota(size)
# Allocate a new temporary file
- f = self.backend.tempfile(delete=False)
-
- upload = self._get_upload("""
- INSERT INTO
- uploads
- (
+ async with self.backend.tempfile(delete=False) as f:
+ upload = self._get_upload("""
+ INSERT INTO
+ uploads
+ (
+ filename,
+ path,
+ size,
+ builder_id,
+ user_id
+ )
+ VALUES
+ (
+ %s,
+ %s,
+ %s,
+ %s,
+ %s
+ )
+ RETURNING *""",
filename,
- path,
+ f.name,
size,
- builder_id,
- user_id
+ builder,
+ user,
)
- VALUES
- (
- %s,
- %s,
- %s,
- %s,
- %s
- )
- RETURNING *""",
- filename,
- f.name,
- size,
- builder,
- user,
- )
# Return the newly created upload object
return upload
size = os.path.getsize(path)
# Create the new upload object
- upload = self.create(filename=filename, size=size, **kwargs)
+ upload = await self.create(filename=filename, size=size, **kwargs)
# Import the data
with open(path, "rb") as f:
# Create a new upload
with self.db.transaction():
try:
- upload = self.backend.uploads.create(
+ upload = await self.backend.uploads.create(
filename,
size=size,
owner=self.current_user,
payload = io.BytesIO(b"012345678901234567890123456789")
with self.db.transaction():
- upload = self.backend.uploads.create("test.blob", size=20, owner=self.user)
+ upload = await self.backend.uploads.create("test.blob", size=20, owner=self.user)
# Try to write more than 20 bytes
with self.assertRaises(OverflowError):
payload = io.BytesIO(b"01234567890123456789")
with self.db.transaction():
- upload = self.backend.uploads.create("test.blob", size=20, owner=self.user)
+ upload = await self.backend.uploads.create("test.blob", size=20, owner=self.user)
# Write some payload
await upload.copyfrom(payload)
# Create an upload that is 200 MiB large
with self.db.transaction():
with self.assertRaises(users.QuotaExceededError):
- self.backend.uploads.create(
+ await self.backend.uploads.create(
"test.blob",
size=209715200,
owner=self.user,