comparison frontends/src/jp/cmd_info.py @ 1414:159d16336f87

core, bridge, jp: management of service discovery extensions (XEP-0128)
author Goffi <goffi@goffi.org>
date Fri, 17 Apr 2015 22:59:35 +0200
parents 069ad98b360d
children d17772b0fe22
comparison
equal deleted inserted replaced
1413:e5393b12dd0f 1414:159d16336f87
15 # GNU Affero General Public License for more details. 15 # GNU Affero General Public License for more details.
16 16
17 # You should have received a copy of the GNU Affero General Public License 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/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from logging import debug, info, error, warning 20 from logging import debug, info, warning
21 21
22 import base 22 import base
23 from sat.core.i18n import _ 23 from sat.core.i18n import _
24 24
25 __commands__ = ["Info"] 25 __commands__ = ["Info"]
46 46
47 def gotInfos(self, infos, jid): 47 def gotInfos(self, infos, jid):
48 self.host.bridge.discoItems(jid, profile_key=self.host.profile, callback=lambda items: self.gotItems(infos, items), errback=self.error) 48 self.host.bridge.discoItems(jid, profile_key=self.host.profile, callback=lambda items: self.gotItems(infos, items), errback=self.error)
49 49
50 def gotItems(self, infos, items): 50 def gotItems(self, infos, items):
51 features, identities = infos 51 features, identities, extensions = infos
52 features.sort() 52 features.sort()
53 identities.sort(key=lambda identity: identity[2]) 53 identities.sort(key=lambda identity: identity[2])
54 items.sort(key=lambda item: item[2]) 54 items.sort(key=lambda item: item[2])
55 identities_lst = [] 55 identities_lst = []
56 items_lst = [] 56 items_lst = []
57 for identity in identities: 57 for identity in identities:
58 category, type_, name = identity 58 category, type_, name = identity
59 identities_lst.append(u"%(name)s(%(cat)s/%(type)s)" % 59 identities_lst.append(u"{name}({cat}/{type_})".format(
60 {'name': (name+' ') if name else '', 60 name = (name+' ') if name else '',
61 'cat': category, 61 cat = category,
62 'type': type_}) 62 type_ = type_))
63 for item in items: 63 for item in items:
64 entity, node_id, name = item 64 entity, node_id, name = item
65 items_lst.append(u"%(name)s[%(entity)s%(node_id)s]" % 65 items_lst.append(u"{name}[{entity}{node_id}]".format(
66 {'name': (name+' ') if name else '', 66 name = (name+' ') if name else '',
67 'entity': entity, 67 entity = entity,
68 'node_id': (', ' + node_id) if node_id else '' 68 node_id = (', ' + node_id) if node_id else ''
69 }) 69 ))
70 extensions_types = extensions.keys()
71 extensions_types.sort()
72
73 extensions_tpl = []
74 for type_ in extensions_types:
75 fields = []
76 for field in extensions[type_]:
77 field_lines = []
78 data, values = field
79 data_keys = data.keys()
80 data_keys.sort()
81 for key in data_keys:
82 field_lines.append(u'\t{key} = {value}'.format(key=key, value=data[key]))
83 for value in values:
84 field_lines.append(u'\tvalue = {value}'.format(value=value))
85 fields.append(u'\n'.join(field_lines))
86 extensions_tpl.append(u'{type_}\n{fields}'.format(type_=type_,
87 fields='\n\n'.join(fields)))
70 88
71 template = [] 89 template = []
72 if features: 90 if features:
73 template.append(_(u"Features:\n\n%(features)s")) 91 template.append(_(u"Features:\n\n{features}"))
74 if identities: 92 if identities:
75 template.append(_(u"Identities:\n\n%(identities)s")) 93 template.append(_(u"Identities:\n\n{identities}"))
94 if extensions_tpl:
95 template.append(_(u'Extensions:\n\n{extensions}'))
76 if items: 96 if items:
77 template.append(_(u"Items:\n\n%(items)s")) 97 template.append(_(u"Items:\n\n{items}"))
78 98
79 print "\n--\n".join(template) % { 'features': '\n'.join(features), 99 print "\n--\n".join(template).format ( features = '\n'.join(features),
80 'identities': '\n'.join(identities_lst), 100 identities = '\n'.join(identities_lst),
81 'items': '\n'.join(items_lst), 101 extensions = '\n'.join(extensions_tpl),
82 } 102 items = '\n'.join(items_lst),
103 )
83 self.host.quit() 104 self.host.quit()
84 105
85 106
86 class Version(base.CommandBase): 107 class Version(base.CommandBase):
87 108