]> git.ipfire.org Git - pakfire.git/commitdiff
client: Rewrite connection check
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Dec 2016 23:59:36 +0000 (00:59 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Dec 2016 23:59:36 +0000 (00:59 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/cli.py
src/pakfire/client.py
src/pakfire/hub.py

index 25086a5c2783bbb513a1c2899d6a8c25e7b329c4..9f3e367f4bbc341026fc5442cb58634ca2a06090 100644 (file)
@@ -893,7 +893,6 @@ class CliClient(Cli):
 
                self.action2func = {
                        "build"       : self.handle_build,
-                       "conn-check"  : self.handle_connection_check,
                        "info"        : self.handle_info,
                        "jobs_show"   : self.handle_jobs_show,
                        "jobs_active" : self.handle_jobs_active,
@@ -930,9 +929,9 @@ class CliClient(Cli):
 
        def parse_command_connection_check(self):
                # Implement the "conn-check" command.
-               sub_conn_check = self.sub_commands.add_parser("conn-check",
-                       help=_("Check the connection to the hub."))
-               sub_conn_check.add_argument("action", action="store_const", const="conn-check")
+               sub_conn_check = self.sub_commands.add_parser("check-connection",
+                       help=_("Check the connection to the hub"))
+               sub_conn_check.set_defaults(func=self.handle_check_connection)
 
        def parse_command_jobs(self):
                sub_jobs = self.sub_commands.add_parser("jobs",
@@ -1055,35 +1054,11 @@ class CliClient(Cli):
                for line in ret:
                        print(line)
 
-       def handle_connection_check(self):
-               ret = []
-
-               address = self.client.get_my_address()
-               ret.append("  %-20s: %s" % (_("Your IP address"), address))
-               ret.append("")
-
-               authenticated = self.client.check_auth()
-               if authenticated:
-                       ret.append("  %s" % _("You are authenticated to the build service:"))
-
-                       user = self.client.get_user_profile()
-                       assert user, "Could not fetch user infomation"
-
-                       keys = [
-                               ("name",       _("User name")),
-                               ("realname",   _("Real name")),
-                               ("email",      _("Email address")),
-                               ("registered", _("Registered")),
-                       ]
-
-                       for key, desc in keys:
-                               ret.append("    %-18s: %s" % (desc, user.get(key)))
-
-               else:
-                       ret.append(_("You could not be authenticated to the build service."))
+       def handle_check_connection(self, ns):
+               success = self.client.check_connection()
 
-               for line in ret:
-                       print(line)
+               if success:
+                       print("%s: %s" % (_("Connection OK"), success))
 
        def _print_jobs(self, jobs, heading=None):
                if heading:
index 8bc5ba9062cc75c0017191d6baab4a023d8e4ae7..fe38dd0b58391a22c4f9fa81ad004fa13cb2f040 100644 (file)
@@ -53,6 +53,12 @@ class Client(object):
                # Create connection to the hub.
                return hub.Hub(huburl, username, password)
 
+       def check_connection(self):
+               """
+                       Tests the connection to the hub
+               """
+               return self.hub.test()
+
        def create_build(self, filename, **kwargs):
                build_id = self.hub.create_build(filename, **kwargs)
 
index c54808332cde269b04194285bd1fbff209b32af2..5c9336a5da2b97c0a297154648dbea6311fe7638 100644 (file)
@@ -58,7 +58,9 @@ class Hub(object):
                """
                        Tests the connection
                """
-               return self._request("/noop")
+               s = self._request("/noop")
+
+               return s.decode("ascii")
 
        def test_error(self, code):
                assert code >= 100 and code <= 999