From 326de0f16155dc8a5729bffe0057282c3232141b Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 14 Mar 2018 17:18:46 +0100 Subject: Factorise the /version callback and make it handle errors Fixes #3376. --- poezio/tabs/conversationtab.py | 16 ++-------------- poezio/tabs/muctab.py | 15 ++------------- poezio/tabs/privatetab.py | 16 ++-------------- 3 files changed, 6 insertions(+), 41 deletions(-) (limited to 'poezio/tabs') diff --git a/poezio/tabs/conversationtab.py b/poezio/tabs/conversationtab.py index 8b713b2d..a8a22b4a 100644 --- a/poezio/tabs/conversationtab.py +++ b/poezio/tabs/conversationtab.py @@ -19,7 +19,6 @@ import curses from poezio.tabs.basetabs import OneToOneTab, Tab from poezio import common -from poezio import fixes from poezio import windows from poezio import xhtml from poezio.common import safeJID @@ -240,18 +239,6 @@ class ConversationTab(OneToOneTab): """ /version [jid] """ - - def callback(res): - if not res: - return self.core.information( - 'Could not get the software version from %s' % (jid, ), - 'Warning') - version = '%s is running %s version %s on %s' % ( - jid, res.get('name') or 'an unknown software', - res.get('version') or 'unknown', - res.get('os') or 'an unknown platform') - self.core.information(version, 'Info') - if args: return self.core.command.version(args[0]) jid = safeJID(self.name) @@ -259,7 +246,8 @@ class ConversationTab(OneToOneTab): if jid in roster: resource = roster[jid].get_highest_priority_resource() jid = resource.jid if resource else jid - fixes.get_version(self.core.xmpp, jid, callback=callback) + self.core.xmpp.plugin['xep_0092'].get_version( + jid, callback=self.core.handler.on_version_result) @command_args_parser.ignored def command_add(self): diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index afe62188..59ef9054 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -1340,18 +1340,6 @@ class MucTab(ChatTab): """ /version """ - - def callback(res): - if not res: - return self.core.information('Could not get the software ' - 'version from %s' % (jid, ), - 'Warning') - version = '%s is running %s version %s on %s' % ( - jid, res.get('name') or 'an unknown software', - res.get('version') or 'unknown', - res.get('os') or 'an unknown platform') - self.core.information(version, 'Info') - if args is None: return self.core.command.help('version') nick = args[0] @@ -1360,7 +1348,8 @@ class MucTab(ChatTab): jid = safeJID(jid + '/' + nick) else: jid = safeJID(nick) - fixes.get_version(self.core.xmpp, jid, callback=callback) + self.core.xmpp.plugin['xep_0092'].get_version( + jid, callback=self.core.handler.on_version_result) @command_args_parser.quoted(1) def command_nick(self, args): diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py index 96c68562..d0a12232 100644 --- a/poezio/tabs/privatetab.py +++ b/poezio/tabs/privatetab.py @@ -17,7 +17,6 @@ import curses from poezio.tabs import OneToOneTab, MucTab, Tab -from poezio import fixes from poezio import windows from poezio import xhtml from poezio.common import safeJID @@ -207,22 +206,11 @@ class PrivateTab(OneToOneTab): """ /version """ - - def callback(res): - if not res: - return self.core.information( - 'Could not get the software version from %s' % (jid, ), - 'Warning') - version = '%s is running %s version %s on %s' % ( - jid, res.get('name') or 'an unknown software', - res.get('version') or 'unknown', - res.get('os') or 'an unknown platform') - self.core.information(version, 'Info') - if args: return self.core.command.version(args[0]) jid = safeJID(self.name) - fixes.get_version(self.core.xmpp, jid, callback=callback) + self.core.xmpp.plugin['xep_0092'].get_version( + jid, callback=self.core.handler.on_version_result) @command_args_parser.quoted(0, 1) def command_info(self, arg): -- cgit v1.2.3