From: Michael Tremer Date: Tue, 18 Oct 2022 17:06:30 +0000 (+0000) Subject: packages: Create packages from uploads only X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f631d9f6b64450b461fb94620f3bc635a50657aa;p=pbs.git packages: Create packages from uploads only This avoids a lot of code duplication Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/packages.py b/src/buildservice/packages.py index aebb03c3..a9d8b676 100644 --- a/src/buildservice/packages.py +++ b/src/buildservice/packages.py @@ -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() diff --git a/src/hub/builds.py b/src/hub/builds.py index 51823beb..49cf54b3 100644 --- a/src/hub/builds.py +++ b/src/hub/builds.py @@ -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 diff --git a/tests/test.py b/tests/test.py index b681af3b..c0817ba2 100644 --- a/tests/test.py +++ b/tests/test.py @@ -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)