From: Michael Tremer Date: Sun, 23 Oct 2022 17:12:21 +0000 (+0000) Subject: client: Implement deleting uploads X-Git-Tag: 0.9.28~241 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21a47e817e6ac9987eab1dfff2113500cff4de42;p=pakfire.git client: Implement deleting uploads Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/client.py b/src/pakfire/client.py index 9eb4764d4..a11be05c5 100644 --- a/src/pakfire/client.py +++ b/src/pakfire/client.py @@ -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): diff --git a/src/pakfire/hub.py b/src/pakfire/hub.py index fefa1064c..e80a070ff 100644 --- a/src/pakfire/hub.py +++ b/src/pakfire/hub.py @@ -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 diff --git a/src/scripts/pakfire-client.in b/src/scripts/pakfire-client.in index 7839550c9..1cff5f3fa 100644 --- a/src/scripts/pakfire-client.in +++ b/src/scripts/pakfire-client.in @@ -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])