Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0092.py @ 920:45dffd67a18a
plugin XEP-0092: new plugin (software version)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 22 Mar 2014 13:44:33 +0100 |
parents | |
children | d609581bf74a |
comparison
equal
deleted
inserted
replaced
919:ed9841e6d84a | 920:45dffd67a18a |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SàT plugin for Software Version (XEP-0092) | |
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 from sat.core.i18n import _ | |
21 from sat.core.constants import Const as C | |
22 from wokkel import disco, iwokkel, data_form, compat | |
23 from sat.core import exceptions | |
24 from logging import debug, info, warning, error | |
25 | |
26 NS_VERSION = "jabber:iq:version" | |
27 | |
28 PLUGIN_INFO = { | |
29 "name": "Software Version Plugin", | |
30 "import_name": "XEP-0092", | |
31 "type": "XEP", | |
32 "protocols": ["XEP-0092"], | |
33 "dependencies": [], | |
34 "main": "XEP_0092", | |
35 "handler": "no", # version is already handler in core.xmpp module | |
36 "description": _("""Implementation of Software Version""") | |
37 } | |
38 | |
39 | |
40 class XEP_0092(object): | |
41 | |
42 def __init__(self, host): | |
43 info(_("Plugin XEP_0092 initialization")) | |
44 self.host = host | |
45 | |
46 def getVersion(self, jid_, profile_key=C.PROF_KEY_NONE): | |
47 """ Ask version of the client that jid_ is running | |
48 @param jid_: jid from who we want to know client's version | |
49 @param profile_key: %(doc_profile_key)s | |
50 @return: a defered which fire tuple with the following data (None if not available): | |
51 - name: Natural language name of the software | |
52 - version: specific version of the software | |
53 - os: operating system of the queried entity | |
54 """ | |
55 client = self.host.getClient(profile_key) | |
56 if not client: | |
57 raise exceptions.ProfileUnknownError | |
58 iq_elt = compat.IQ(client.xmlstream, 'get') | |
59 iq_elt['to'] = jid_.full() | |
60 query_elt = iq_elt.addElement("query", NS_VERSION) | |
61 d = iq_elt.send() | |
62 d.addCallback(self._gotVersion) | |
63 return d | |
64 | |
65 def _gotVersion(self, iq_elt): | |
66 try: | |
67 query_elt = iq_elt.elements(NS_VERSION, 'query').next() | |
68 except StopIteration: | |
69 raise exceptions.DataError | |
70 ret = [] | |
71 for name in ('name', 'version', 'os'): | |
72 try: | |
73 data_elt = query_elt.elements(NS_VERSION, name).next() | |
74 ret.append(unicode(data_elt)) | |
75 except StopIteration: | |
76 ret.append(None) | |
77 | |
78 return tuple(ret) | |
79 | |
80 |