From: Michael Tremer Date: Thu, 1 Dec 2016 23:59:36 +0000 (+0100) Subject: client: Rewrite connection check X-Git-Tag: 0.9.28~1285^2~1436 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e3e13fb805906724dd222d8457e730159940122;p=pakfire.git client: Rewrite connection check Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/cli.py b/src/pakfire/cli.py index 25086a5c2..9f3e367f4 100644 --- a/src/pakfire/cli.py +++ b/src/pakfire/cli.py @@ -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: diff --git a/src/pakfire/client.py b/src/pakfire/client.py index 8bc5ba906..fe38dd0b5 100644 --- a/src/pakfire/client.py +++ b/src/pakfire/client.py @@ -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) diff --git a/src/pakfire/hub.py b/src/pakfire/hub.py index c54808332..5c9336a5d 100644 --- a/src/pakfire/hub.py +++ b/src/pakfire/hub.py @@ -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