]> git.ipfire.org Git - pbs.git/commitdiff
packages: Create packages from uploads only
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 18 Oct 2022 17:06:30 +0000 (17:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 18 Oct 2022 17:06:30 +0000 (17:06 +0000)
This avoids a lot of code duplication

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/packages.py
src/hub/builds.py
tests/test.py

index aebb03c3b9323d54bef13e75ae1703b5cb73a3af..a9d8b676a77c6b949b8102ec7ba024aebe39bc75 100644 (file)
@@ -73,7 +73,17 @@ class Packages(base.Object):
                        """, uuid,
                )
 
-       async def create(self, archive):
+       async def create(self, upload):
+               """
+                       Creates a new package from an uploaded file
+               """
+               # Check if the upload has been completed
+               if not upload.is_completed():
+                       raise RuntimeError("Cannot import package from incomplete upload")
+
+               # Upload the archive
+               archive = await self.backend.open(upload.path)
+
                # Extract package metadata from archive
                package = archive.get_package()
 
index 51823bebf54066ec036a17ee77af57807aa22ae8..49cf54b33589f95987dd7b74a832a12f8cd991a4 100644 (file)
@@ -35,14 +35,8 @@ class CreateHandler(BaseHandler):
                        raise tornado.web.HTTPError(403, "No permission for using upload %s" % upload)
 
                with self.db.transaction():
-                       # Try opening the archive
-                       archive = await self.backend.open(upload.path)
-
-                       # Extract the package metadata
-                       package = archive.get_package()
-
                        # Import the package
-                       package = await self.backend.packages.create(archive)
+                       package = await self.backend.packages.create(upload)
 
                        # XXX Fetch the distribution
                        # XXX Fetch the repository
index b681af3baaf62fa0f5106fda0ca1d9f761e5edeb..c0817ba20c961557c0aa667772efad14e267188a 100644 (file)
@@ -144,14 +144,11 @@ class TestCase(unittest.IsolatedAsyncioTestCase):
                # Check if the file exists
                self.assertTrue(os.path.exists(path))
 
-               # Open the archive
-               archive = await self.backend.open(path)
-
-               # Check if we received the correct type
-               self.assertIsInstance(archive, Archive)
+               # Upload the file
+               upload = await self._create_upload(path)
 
                # Create the package
-               package = await self.backend.packages.create(archive)
+               package = await self.backend.packages.create(upload)
 
                # Check if we received the correct type
                self.assertIsInstance(package, packages.Package)