]> git.ipfire.org Git - pakfire.git/commitdiff
client: Implement deleting uploads
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 17:12:21 +0000 (17:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 17:12:21 +0000 (17:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/client.py
src/pakfire/hub.py
src/scripts/pakfire-client.in

index 9eb4764d4064835ae8273f821efdbcfb1e103cf9..a11be05c55de36e4fdf4f6965da946729a92f172 100644 (file)
@@ -71,6 +71,9 @@ class Client(object):
        def upload(self, *args, **kwargs):
                return self.hub.upload(*args, **kwargs)
 
+       def delete_upload(self, *args, **kwargs):
+               return self.hub.delete_upload(*args, **kwargs)
+
 
 class _ClientObject(object):
        def __init__(self, client, id):
index fefa1064c35984742b82c65d8f4daee0a9c22313..e80a070ff5037244c2d6ad3f249d440d1245f9b2 100644 (file)
@@ -83,7 +83,7 @@ class Hub(object):
                query_args = urllib.parse.urlencode(kwargs)
 
                # Add query arguments
-               if method in ("GET", "PUT"):
+               if method in ("GET", "PUT", "DELETE"):
                        url = "%s?%s" % (url, query_args)
 
                # Add any arguments to the body
@@ -265,6 +265,9 @@ class Hub(object):
                # Return the upload ID
                return response.get("id")
 
+       async def delete_upload(self, upload_id):
+               await self._request("DELETE", "/uploads", id=upload_id)
+
        @staticmethod
        def _stream_file(path, size, p, write):
                # Start the progressbar
index 7839550c9c2a678f8728568a2fbee09d4cac0b55..1cff5f3fa497b9cfce333275c20775e310d13da7 100644 (file)
@@ -59,6 +59,13 @@ class Cli(object):
                        help=_("Filename"))
                upload.set_defaults(func=self._upload)
 
+               # delete-upload
+               upload_delete = subparsers.add_parser("delete-upload",
+                       help=_("Delete an upload"))
+               upload_delete.add_argument("upload_id", metavar="ID", nargs="+",
+                       help=_("One or multiple IDs"))
+               upload_delete.set_defaults(func=self._delete_upload)
+
                # watch-build
                watch_build = subparsers.add_parser("watch-build",
                        help=_("Watch the status of a build"))
@@ -124,6 +131,8 @@ class Cli(object):
                except KeyError:
                        pass
 
+       # Uploads
+
        async def _upload(self, client, ns):
                for file in ns.file:
                        upload_id = await client.upload(file)
@@ -135,6 +144,15 @@ class Cli(object):
                                }
                        )
 
+       async def _delete_upload(self, client, ns):
+               """
+                       Delete uploads
+               """
+               for upload_id in ns.upload_id:
+                       await client.delete_upload(upload_id)
+
+                       print(_("Deleted upload %s") % upload_id)
+
        async def _watch_build(self, client, ns):
                build = client.get_build(ns.id[0])