From: Michael Tremer Date: Thu, 26 May 2022 08:59:58 +0000 (+0000) Subject: client: Make all functions async X-Git-Tag: 0.9.28~754 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7eca0c023ac5cd7792ccfb1f617db1f73a507ca;p=pakfire.git client: Make all functions async Signed-off-by: Michael Tremer --- diff --git a/src/scripts/pakfire-client.in b/src/scripts/pakfire-client.in index 9bec6154e..597f9318d 100644 --- a/src/scripts/pakfire-client.in +++ b/src/scripts/pakfire-client.in @@ -19,6 +19,7 @@ # # ############################################################################### +import asyncio import argparse import os.path import sys @@ -88,7 +89,7 @@ class Cli(object): # Call function try: - ret = args.func(client, args) + ret = asyncio.run(args.func(client, args)) # Catch invalid inputs except ValueError as e: @@ -98,7 +99,7 @@ class Cli(object): # Return with exit code sys.exit(ret or 0) - def _build(self, client, ns): + async def _build(self, client, ns): # Create a temporary directory. temp_dir = tempfile.mkdtemp() @@ -141,27 +142,34 @@ class Cli(object): if os.path.exists(temp_dir): shutil.rmtree(temp_dir, ignore_errors=True) - def _check_connection(self, client, ns): + async def _check_connection(self, client, ns): success = client.check_connection() if success: print("%s: %s" % (_("Connection OK"), success)) - def _upload(self, client, ns): - for path in ns.file: - client.upload_file(path) + async def _upload(self, client, ns): + for file in ns.file: + upload_id = await client.upload(file) - def _watch_build(self, client, ns): + # Tell the user + print(_("%(file)s uploaded as %(id)s") % { + "file" : file, + "id" : upload_id, + } + ) + + async def _watch_build(self, client, ns): build = client.get_build(ns.id[0]) return self._watch_something(build) - def _watch_job(self, client, ns): + async def _watch_job(self, client, ns): job = client.get_job(ns.id[0]) return self._watch_something(job) - def _watch_something(self, o): + async def _watch_something(self, o): while True: s = o.dump() print(s)