]> git.ipfire.org Git - pakfire.git/commitdiff
client: Make all functions async
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 May 2022 08:59:58 +0000 (08:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 May 2022 08:59:58 +0000 (08:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/pakfire-client.in

index 9bec6154e591239aa72eb0a455f64d5623625c4b..597f9318d61b94f09454ba5b8d49d44cdc29f3a4 100644 (file)
@@ -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)