Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0092.py @ 948:abd3a75d629c
plugin account: prosody gid is used to spawn prosodyctl process
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 31 Mar 2014 12:23:10 +0200 |
parents | 899dc9cd0f35 |
children | 91836a647515 |
rev | line source |
---|---|
920
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # SàT plugin for Software Version (XEP-0092) |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from sat.core.i18n import _ |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from sat.core.constants import Const as C |
945
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
22 from wokkel import compat |
920
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat.core import exceptions |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from logging import debug, info, warning, error |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 NS_VERSION = "jabber:iq:version" |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 PLUGIN_INFO = { |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 "name": "Software Version Plugin", |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 "import_name": "XEP-0092", |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 "type": "XEP", |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 "protocols": ["XEP-0092"], |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 "dependencies": [], |
926
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
34 "recommendations": [C.TEXT_CMDS], |
920
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 "main": "XEP_0092", |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 "handler": "no", # version is already handler in core.xmpp module |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 "description": _("""Implementation of Software Version""") |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 } |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 class XEP_0092(object): |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 def __init__(self, host): |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 info(_("Plugin XEP_0092 initialization")) |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 self.host = host |
926
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
46 try: |
928
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
47 self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 50) |
926
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
48 except KeyError: |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
49 info(_("Text commands not available")) |
920
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 def getVersion(self, jid_, profile_key=C.PROF_KEY_NONE): |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 """ Ask version of the client that jid_ is running |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 @param jid_: jid from who we want to know client's version |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 @param profile_key: %(doc_profile_key)s |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 @return: a defered which fire tuple with the following data (None if not available): |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 - name: Natural language name of the software |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 - version: specific version of the software |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 - os: operating system of the queried entity |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 """ |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 client = self.host.getClient(profile_key) |
945
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
61 def getVersion(available): |
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
62 if not available: |
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
63 raise exceptions.FeatureNotFound |
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
64 iq_elt = compat.IQ(client.xmlstream, 'get') |
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
65 iq_elt['to'] = jid_.full() |
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
66 iq_elt.addElement("query", NS_VERSION) |
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
67 d = iq_elt.send() |
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
68 d.addCallback(self._gotVersion) |
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
69 return d |
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
70 d = self.host.hasFeature(NS_VERSION, jid_, client.profile) |
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
71 d.addCallback(getVersion) |
920
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 return d |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 def _gotVersion(self, iq_elt): |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 try: |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 query_elt = iq_elt.elements(NS_VERSION, 'query').next() |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 except StopIteration: |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 raise exceptions.DataError |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 ret = [] |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 for name in ('name', 'version', 'os'): |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 try: |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 data_elt = query_elt.elements(NS_VERSION, name).next() |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 ret.append(unicode(data_elt)) |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 except StopIteration: |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 ret.append(None) |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 return tuple(ret) |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 |
45dffd67a18a
plugin XEP-0092: new plugin (software version)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 |
928
73873e9b56f7
plugin XEP-0045: added user information to /whois text command
Goffi <goffi@goffi.org>
parents:
926
diff
changeset
|
90 def _whois(self, whois_msg, mess_data, target_jid, profile): |
926
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
91 """ Add software/OS information to whois """ |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
92 def versionCb(version_data): |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
93 name, version, os = version_data |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
94 if name: |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
95 whois_msg.append(_("Client name: %s") % name) |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
96 if version: |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
97 whois_msg.append(_("Client version: %s") % version) |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
98 if os: |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
99 whois_msg.append(_("Operating system: %s") % os) |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
100 def versionEb(failure): |
945
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
101 failure.trap(exceptions.FeatureNotFound) |
899dc9cd0f35
plugin XEP-0092: feature check before requesting version
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
102 whois_msg.append(_("Software informations not available")) |
926
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
103 |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
104 d = self.getVersion(target_jid, profile) |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
105 d.addCallbacks(versionCb, versionEb) |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
106 return d |
d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
Goffi <goffi@goffi.org>
parents:
920
diff
changeset
|
107 |