From 6e58f88d051067c2a833d53343fa6d27d58213f7 Mon Sep 17 00:00:00 2001 From: mathieui Date: Tue, 10 May 2011 00:47:41 +0200 Subject: Fix the /version command in mucs (and globaaly) & improve shlex parsing --- src/common.py | 6 ++++-- src/core.py | 2 +- src/tabs.py | 28 +++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/common.py b/src/common.py index 03c9b6a4..6a9d4a9c 100644 --- a/src/common.py +++ b/src/common.py @@ -194,7 +194,9 @@ def datetime_tuple(timestamp): return ret def shell_split(string): - sh = shlex.shlex(string, posix=True) + sh = shlex.shlex(string, posix=False) + sh.whitespace_split = True + sh.quotes = '"' ret = list() try: w = sh.get_token() @@ -203,7 +205,7 @@ def shell_split(string): w = sh.get_token() return ret except ValueError: - return string.split() + return string.split(" ") def curses_color_pair(color): if color < 0: diff --git a/src/core.py b/src/core.py index c000fd55..6cb6efa5 100644 --- a/src/core.py +++ b/src/core.py @@ -1044,7 +1044,7 @@ class Core(object): """ /version """ - args = arg.split() + args = common.shell_split(arg) if len(args) < 1: return self.command_help('version') jid = args[0] diff --git a/src/tabs.py b/src/tabs.py index af468d8c..aa752ee5 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -135,10 +135,10 @@ class Tab(object): not txt.startswith('/me '): command = txt.strip().split()[0][1:] arg = txt[2+len(command):] # jump the '/' and the ' ' - if command in self.core.commands: # check global commands - self.core.commands[command][0](arg) - elif command in self.commands: # check tab-specific commands + if command in self.commands: # check tab-specific commands self.commands[command][0](arg) + elif command in self.core.commands: # check global commands + self.core.commands[command][0](arg) else: self.core.information(_("Unknown command (%s)") % (command), _('Error')) return True @@ -460,6 +460,7 @@ class MucTab(ChatTab): self.commands['cycle'] = (self.command_cycle, _('Usage: /cycle [message]\nCycle: Leaves the current room and rejoin it immediately'), None) self.commands['info'] = (self.command_info, _('Usage: /info \nInfo: Display some information about the user in the MUC: his/here role, affiliation, status and status message.'), None) self.commands['configure'] = (self.command_configure, _('Usage: /configure\nConfigure: Configure the current room, through a form.'), None) + self.commands['version'] = (self.command_version, _('Usage: /version \nVersion: get the software version of the given JID or nick in room (usually its XMPP client and Operating System)'), None) self.resize() def scroll_user_list_up(self): @@ -527,6 +528,27 @@ class MucTab(ChatTab): self.text_win.refresh(self._room) self.input.refresh() + def command_version(self, arg): + """ + /version + """ + args = common.shell_split(arg) + if len(args) < 1: + return + log.debug('ALLO: %s' % args[0]) + if args[0] in [user.nick for user in self.get_room().users]: + jid = self._room.name + '/' + args[0] + else: + jid = args[0] + res = self.core.xmpp.plugin['xep_0092'].get_version(jid) + 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 _('on an unknown platform')) + self.core.information(version, 'Info') + def command_nick(self, arg): """ /nick -- cgit v1.2.3