]> git.ipfire.org Git - pakfire.git/commitdiff
client: Drop wrapper class and connect straight to the hub
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 17:22:29 +0000 (17:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 17:22:29 +0000 (17:22 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/pakfire/client.py [deleted file]
src/scripts/pakfire-client.in

index 0f26c83fa230a58e6e71a732a3ef28190b1df694..42ca63c758859b2f32befcf57e8f2c888423a843 100644 (file)
@@ -124,7 +124,6 @@ CLEANFILES += \
 pakfire_PYTHON = \
        src/pakfire/__init__.py \
        src/pakfire/__version__.py \
-       src/pakfire/client.py \
        src/pakfire/config.py \
        src/pakfire/constants.py \
        src/pakfire/daemon.py \
diff --git a/src/pakfire/client.py b/src/pakfire/client.py
deleted file mode 100644 (file)
index a11be05..0000000
+++ /dev/null
@@ -1,296 +0,0 @@
-#!/usr/bin/python3
-###############################################################################
-#                                                                             #
-# Pakfire - The IPFire package management system                              #
-# Copyright (C) 2013 Pakfire development team                                 #
-#                                                                             #
-# This program is free software: you can redistribute it and/or modify        #
-# it under the terms of the GNU General Public License as published by        #
-# the Free Software Foundation, either version 3 of the License, or           #
-# (at your option) any later version.                                         #
-#                                                                             #
-# This program is distributed in the hope that it will be useful,             #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
-# GNU General Public License for more details.                                #
-#                                                                             #
-# You should have received a copy of the GNU General Public License           #
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
-#                                                                             #
-###############################################################################
-
-import logging
-
-from . import config
-from . import hub
-
-from .constants import *
-from .i18n import _
-
-log = logging.getLogger("pakfire.client")
-log.propagate = 1
-
-class Client(object):
-       def __init__(self, config_file="client.conf"):
-               # Read configuration
-               self.config = config.Config(config_file)
-
-               # Create connection to the hub
-               self.hub = self.connect_to_hub()
-
-       def connect_to_hub(self):
-               huburl = self.config.get("client", "server", PAKFIRE_HUB)
-
-               # keytab
-               keytab = self.config.get("client", "keytab")
-
-               # Create a connection to the hub
-               return hub.Hub(huburl, keytab=keytab)
-
-       async def check_connection(self):
-               """
-                       Tests the connection to the hub
-               """
-               return await self.hub.test()
-
-       # Builds
-
-       async def build(self, *args, **kwargs):
-               return await self.hub.build(*args, **kwargs)
-
-       def get_build(self, build_id):
-               return Build(self, build_id)
-
-       # Jobs
-
-       def get_job(self, job_id):
-               return Job(self, job_id)
-
-       # Uploads
-
-       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):
-               self.client = client
-
-               # UUID of the build
-               self.id = id
-
-               self._data = None
-               self._cache = {}
-
-       def __repr__(self):
-               return "<%s %s>" % (self.__class__.__name__, self.id)
-
-       def __eq__(self, other):
-               return self.id == other.id
-
-       @property
-       def data(self):
-               if self._data is None:
-                       self._data = self._load()
-
-               return self._data
-
-       def refresh(self):
-               self._data = self._load()
-
-       def _load(self):
-               """
-                       Loads information about this object from the hub
-               """
-               raise NotImplementedError
-
-
-class Build(_ClientObject):
-       def _load(self):
-               """
-                       Loads information about this build from the hub
-               """
-               return self.client.hub.get_build(self.id)
-
-       @property
-       def jobs(self):
-               jobs = []
-
-               for job in self.data.get("jobs"):
-                       try:
-                               j = self._cache[job]
-                       except KeyError:
-                               j = Job(self.client, job)
-
-                       jobs.append(j)
-
-               return sorted(jobs)
-
-       @property
-       def type(self):
-               """
-                       The type of this build (release or scratch)
-               """
-               return self.data.get("type")
-
-       @property
-       def _type_tag(self):
-               if self.type == "release":
-                       return "[R]"
-
-               elif self.type == "scratch":
-                       return "[S]"
-
-       @property
-       def name(self):
-               """
-                       The name of this build
-               """
-               return self.data.get("name")
-
-       @property
-       def priority(self):
-               """
-                       The priority of this build
-               """
-               return self.data.get("priority")
-
-       @property
-       def score(self):
-               """
-                       The score of this build
-               """
-               return self.data.get("score")
-
-       @property
-       def state(self):
-               """
-                       The state this build is in
-               """
-               return self.data.get("state")
-
-       def is_active(self):
-               return self.state == "building"
-
-       @property
-       def oneline(self):
-               s = [
-                       self.name,
-                       self._type_tag,
-                       "(%s)" % self.id,
-                       _("Score: %s") % self.score,
-                       _("Priority: %s") % self.priority,
-               ]
-
-               return " ".join(s)
-
-       def dump(self):
-               # Add a headline for the build
-               s = [
-                       self.oneline,
-               ]
-
-               # Add a short line for each job
-               for j in self.jobs:
-                       s.append("  %s" % j.oneline)
-
-               return "\n".join(s)
-
-
-class Job(_ClientObject):
-       def _load(self):
-               """
-                       Loads information about this job from the hub
-               """
-               return self.client.hub.get_job(self.id)
-
-       def __lt__(self, other):
-               return self.arch < other.arch
-
-       @property
-       def name(self):
-               """
-                       The name of this job
-               """
-               return self.data.get("name")
-
-       @property
-       def type(self):
-               """
-                       The type of this build
-               """
-               return self.data.get("type")
-
-       @property
-       def arch(self):
-               """
-                       The architecture of this job
-               """
-               return self.data.get("arch")
-
-       @property
-       def builder(self):
-               """
-                       The name of the builder that built this job
-               """
-               return self.data.get("builder")
-
-       @property
-       def duration(self):
-               """
-                       The duration the job took to build
-               """
-               return self.data.get("duration")
-
-       @property
-       def state(self):
-               """
-                       The state of this job
-               """
-               return self.data.get("state")
-
-       def is_active(self):
-               return self.state in ("dispatching", "running", "uploading")
-
-       def is_finished(self):
-               return self.state == "finished"
-
-       @property
-       def oneline(self):
-               s = [
-                       # Architecture
-                       "[%-8s]" % self.arch,
-
-                       # State
-                       "[%12s]" % self.state,
-               ]
-
-               if self.is_active():
-                       s.append(_("on %s") % self.builder)
-
-               elif self.is_finished():
-                       s.append(_("in %s") % ("%02d:%02d" % (self.duration // 60, self.duration % 60)))
-
-               return " ".join(s)
-
-       def dump(self):
-               s = []
-
-               # Name
-               s.append(self.name)
-
-               # Append tag for test buils
-               if self.type == "test":
-                       s.append("[T]")
-
-               # UUID
-               s.append("(%s)" % self.id)
-
-               # Show the builder for active jobs
-               if self.is_active() and self.builder:
-                       s.append(_("Builder: %s") % self.builder)
-
-               return " ".join(s)
index 1cff5f3fa497b9cfce333275c20775e310d13da7..2845802cf6411827628011e03d4c673d7096d097 100644 (file)
@@ -26,10 +26,16 @@ import sys
 import tempfile
 import time
 
-import pakfire.client
+import pakfire.config
+import pakfire.hub
+
 from pakfire.i18n import _
 
 class Cli(object):
+       def __init__(self):
+               # Read configuration
+               self.config = pakfire.config.Config("client.conf")
+
        def parse_cli(self):
                parser = argparse.ArgumentParser(
                        description = _("Pakfire Client command line interface"),
@@ -93,12 +99,15 @@ class Cli(object):
                # Parse command line arguments
                args = self.parse_cli()
 
-               # Create the Client
-               client = pakfire.client.Client()
+               # Create connection to the hub
+               hub = self.connect_to_hub()
+
+               # Setup the callback
+               callback = args.func(hub, args)
 
                # Call function
                try:
-                       ret = asyncio.run(args.func(client, args))
+                       ret = asyncio.run(callback)
 
                # Catch invalid inputs
                except ValueError as e:
@@ -108,7 +117,19 @@ class Cli(object):
                # Return with exit code
                sys.exit(ret or 0)
 
-       async def _build(self, client, ns):
+       def connect_to_hub(self):
+               """
+                       Establishes a connection to the hub
+               """
+               huburl = self.config.get("client", "server", "https://pakfirehub.ipfire.org")
+
+               # keytab
+               keytab = self.config.get("client", "keytab")
+
+               # Create a connection to the hub
+               return pakfire.hub.Hub(huburl, keytab=keytab)
+
+       async def _build(self, hub, ns):
                # Create a temporary directory if we need to call dist
                tmp = tempfile.TemporaryDirectory(prefix="pakfire-client-")
 
@@ -117,13 +138,13 @@ class Cli(object):
 
                        # Build all packages
                        for package in ns.packages:
-                               await client.build(package, arches=ns.arch, repo=ns.repo)
+                               await hub.build(package, arches=ns.arch, repo=ns.repo)
 
                finally:
                        tmp.cleanup()
 
-       async def _check_connection(self, client, ns):
-               response = await client.check_connection()
+       async def _check_connection(self, hub, ns):
+               response = await hub.check_connection()
 
                # Print the response from the service
                try:
@@ -133,9 +154,9 @@ class Cli(object):
 
        # Uploads
 
-       async def _upload(self, client, ns):
+       async def _upload(self, hub, ns):
                for file in ns.file:
-                       upload_id = await client.upload(file)
+                       upload_id = await hub.upload(file)
 
                        # Tell the user
                        print(_("%(file)s uploaded as %(id)s") % {
@@ -144,22 +165,22 @@ class Cli(object):
                                }
                        )
 
-       async def _delete_upload(self, client, ns):
+       async def _delete_upload(self, hub, ns):
                """
                        Delete uploads
                """
                for upload_id in ns.upload_id:
-                       await client.delete_upload(upload_id)
+                       await hub.delete_upload(upload_id)
 
                        print(_("Deleted upload %s") % upload_id)
 
-       async def _watch_build(self, client, ns):
-               build = client.get_build(ns.id[0])
+       async def _watch_build(self, hub, ns):
+               build = hub.get_build(ns.id[0])
 
                return self._watch_something(build)
 
-       async def _watch_job(self, client, ns):
-               job = client.get_job(ns.id[0])
+       async def _watch_job(self, hub, ns):
+               job = hub.get_job(ns.id[0])
 
                return self._watch_something(job)