annotate frontends/src/jp/cmd_info.py @ 977:d2e612a45e76

tools, frontends (xmlui): add Widget.setInternalCallback: - to add UI callback not communication with the bridge - a list of predefined actions can be used to copy, move, select values - extra data can be passed within the 'internal_data' element TODO: frontend side operation to retrieve the data from node to data structure should be generic
author souliane <souliane@mailoo.org>
date Thu, 03 Apr 2014 14:56:16 +0200
parents 54cd05f68c7c
children 6ec513ad92c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #! /usr/bin/python
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
3
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # jp: a SAT command line tool
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
6
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
11
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
16
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
19
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from logging import debug, info, error, warning
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
21
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import base
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.i18n import _
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
24
971
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
25 __commands__ = ["Info"]
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
26
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
27
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
28 class Disco(base.CommandBase):
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
29
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
30 def __init__(self, host):
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
31 super(Disco, self).__init__(host, 'disco', help=_('Service discovery'))
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
32
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
33 def add_parser_options(self):
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
34 self.parser.add_argument("jid", type=str, help=_("Entity to discover"))
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
35
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
36 def connected(self):
974
54cd05f68c7c jp (info/disco): fixed disco loop when --connect is used
Goffi <goffi@goffi.org>
parents: 971
diff changeset
37 self.need_loop=True
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
38 super(Disco, self).connected()
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
39 jids = self.host.check_jids([self.args.jid])
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
40 jid = jids[0]
971
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
41 self.host.bridge.discoInfos(jid, profile_key=self.host.profile, callback=lambda infos: self.gotInfos(infos, jid), errback=self.error)
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
42
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
43 def error(self, failure):
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
44 print (_("Error while doing discovery"))
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
45 self.host.quit(1)
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
46
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
47 def gotInfos(self, infos, jid):
971
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
48 self.host.bridge.discoItems(jid, profile_key=self.host.profile, callback=lambda items: self.gotItems(infos, items), errback=self.error)
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
49
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
50 def gotItems(self, infos, items):
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
51 features, identities = infos
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
52 features.sort()
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
53 identities.sort(key=lambda identity: identity[2])
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
54 items.sort(key=lambda item: item[2])
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
55 identities_lst = []
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
56 items_lst = []
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
57 for identity in identities:
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
58 category, type_, name = identity
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
59 identities_lst.append(u"%(name)s(%(cat)s/%(type)s)" %
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
60 {'name': (name+' ') if name else '',
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
61 'cat': category,
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
62 'type': type_})
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
63 for item in items:
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
64 entity, node_id, name = item
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
65 items_lst.append(u"%(name)s[%(entity)s%(node_id)s]" %
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
66 {'name': (name+' ') if name else '',
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
67 'entity': entity,
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
68 'node_id': (', ' + node_id) if node_id else ''
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
69 })
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
70
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
71 template = []
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
72 if features:
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
73 template.append(_(u"Features:\n\n%(features)s"))
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
74 if identities:
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
75 template.append(_(u"Identities:\n\n%(identities)s"))
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
76 if items:
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
77 template.append(_(u"Items:\n\n%(items)s"))
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
78
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
79 print "\n--\n".join(template) % { 'features': '\n'.join(features),
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
80 'identities': '\n'.join(identities_lst),
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
81 'items': '\n'.join(items_lst),
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
82 }
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self.host.quit()
971
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
84
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
85
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
86 class Version(base.CommandBase):
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
87
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
88 def __init__(self, host):
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
89 super(Version, self).__init__(host, 'version', help=_('Client version'))
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
90
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
91 def add_parser_options(self):
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
92 self.parser.add_argument("jid", type=str, help=_("Entity to request"))
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
93
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
94 def connected(self):
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
95 self.need_loop=True
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
96 super(Version, self).connected()
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
97 jids = self.host.check_jids([self.args.jid])
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
98 jid = jids[0]
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
99 self.host.bridge.getSoftwareVersion(jid, self.host.profile, callback=self.gotVersion, errback=self.error)
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
100
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
101 def error(self, failure):
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
102 print (_("Error while trying to get version [%s]") % failure)
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
103 self.host.quit(1)
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
104
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
105 def gotVersion(self, data):
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
106 infos = []
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
107 name, version, os = data
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
108 if name:
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
109 infos.append(_("Client name: %s") % name)
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
110 if version:
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
111 infos.append(_("Client version: %s") % version)
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
112 if os:
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
113 infos.append(_("Operating System: %s") % os)
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
114
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
115 print "\n".join(infos)
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
116 self.host.quit()
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
117
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
118
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
119 class Info(base.CommandBase):
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
120 subcommands = (Disco, Version)
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
121
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
122 def __init__(self, host):
8ca5c990ed92 jp: "disco" subcommand, moved into a new "info" subcommand + added "version" subcommand which get software version
Goffi <goffi@goffi.org>
parents: 966
diff changeset
123 super(Info, self).__init__(host, 'info', use_profile=False, help=_('Get various informations on entities'))