From: Michael Tremer Date: Sun, 23 Oct 2022 17:33:25 +0000 (+0000) Subject: client: Add command to list all uploads X-Git-Tag: 0.9.28~237 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3cafdb83d058c0d461f20881f09ea066074e28e5;p=pakfire.git client: Add command to list all uploads Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/hub.py b/src/pakfire/hub.py index e80a070ff..4d47965e3 100644 --- a/src/pakfire/hub.py +++ b/src/pakfire/hub.py @@ -222,7 +222,15 @@ class Hub(object): def get_package(self, uuid): return self._request("/packages/%s" % uuid, decode="json") - # File uploads + # Uploads + + async def list_uploads(self): + """ + Returns a list of all uploads + """ + response = await self._request("GET", "/uploads") + + return response.get("uploads") async def upload(self, path, filename=None, show_progress=True): """ diff --git a/src/scripts/pakfire-client.in b/src/scripts/pakfire-client.in index a7defc3fc..698d238b9 100644 --- a/src/scripts/pakfire-client.in +++ b/src/scripts/pakfire-client.in @@ -62,6 +62,10 @@ class Cli(object): upload_subparsers = upload.add_subparsers() + # upload list + upload_list = upload_subparsers.add_parser("list", help=_("List all uploads")) + upload_list.set_defaults(func=self._upload_list) + # upload new upload_new = upload_subparsers.add_parser("new", help=_("Create a new upload")) upload_new.add_argument("file", nargs="+", help=_("Filename")) @@ -141,6 +145,24 @@ class Cli(object): # Uploads + async def _upload_list(self, hub, ns): + uploads = await hub.list_uploads() + + for upload in uploads: + print(_("Upload %s") % upload.get("id")) + + attributes = { + _("Filename") : upload.get("filename"), + _("Size") : upload.get("size"), + _("Created at") : upload.get("created_at"), + _("Expires at") : upload.get("expires_at"), + } + + for key, val in attributes.items(): + print (" %-20s : %s" % (key, val)) + + print() # newline + async def _upload_new(self, hub, ns): for file in ns.file: upload_id = await hub.upload(file)