annotate sat_frontends/jp/cmd_info.py @ 2635:eecd84a2530a

0.7.0a1 release
author Goffi <goffi@goffi.org>
date Wed, 04 Jul 2018 07:26:20 +0200
parents 87f8cf51fca5
children 263a00e90174
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1960
3e168cde7a7d jp: fixed shebang python call
Goffi <goffi@goffi.org>
parents: 1864
diff changeset
1 #!/usr/bin/env python2
966
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
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
966
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 import base
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core.i18n import _
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
22 from sat.tools.common.ansi import ANSI as A
2600
947c4c4c5c53 jp (info/session): by default, display started as human readable date instead of Unix time
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
23 from sat.tools.common import date_utils
2114
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
24 from sat_frontends.jp.constants import Const as C
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
25 from sat_frontends.jp import common
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
26
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
27 __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
28
966
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 class Disco(base.CommandBase):
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
31
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def __init__(self, host):
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
33 extra_outputs = {'default': self.default_output}
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
34 super(Disco, self).__init__(host, 'disco', use_output='complex', extra_outputs=extra_outputs, help=_('service discovery'))
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
35 self.need_loop=True
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
36
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
37 def add_parser_options(self):
2151
fff88c33442f jp (info/disco): added --node argument
Goffi <goffi@goffi.org>
parents: 2114
diff changeset
38 self.parser.add_argument(u"jid", type=base.unicode_decoder, help=_(u"entity to discover"))
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
39 self.parser.add_argument(u"-t", u"--type", type=str, choices=('infos', 'items', 'both'), default='both', help=_(u"type of data to discover"))
2151
fff88c33442f jp (info/disco): added --node argument
Goffi <goffi@goffi.org>
parents: 2114
diff changeset
40 self.parser.add_argument(u"-n", u"--node", type=base.unicode_decoder, default=u'', help=_(u"node to use"))
2343
ca1ab42c7ae9 jp (info/disco): added --no-cache option
Goffi <goffi@goffi.org>
parents: 2340
diff changeset
41 self.parser.add_argument(u"-C", u"--no-cache", dest='use_cache', action="store_false", help=_(u"ignore cache"))
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
42
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
43 def start(self):
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
44 self.get_infos = self.args.type in ('infos', 'both')
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
45 self.get_items = self.args.type in ('items', 'both')
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
46 jids = self.host.check_jids([self.args.jid])
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
47 jid = jids[0]
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
48 if not self.get_infos:
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
49 self.gotInfos(None, jid)
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
50 else:
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
51 self.host.bridge.discoInfos(jid, node=self.args.node, use_cache=self.args.use_cache, profile_key=self.host.profile, callback=lambda infos: self.gotInfos(infos, jid), errback=self.error)
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
52
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
53 def error(self, failure):
1063
6ec513ad92c2 frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents: 974
diff changeset
54 print (_("Error while doing discovery [%s]") % failure)
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
55 self.host.quit(1)
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
56
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
57 def gotInfos(self, infos, jid):
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
58 if not self.get_items:
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
59 self.gotItems(infos, None)
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
60 else:
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
61 self.host.bridge.discoItems(jid, node=self.args.node, use_cache=self.args.use_cache, 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
62
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
63 def gotItems(self, infos, items):
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
64 data = {}
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
65
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
66 if self.get_infos:
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
67 features, identities, extensions = infos
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
68 features.sort()
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
69 identities.sort(key=lambda identity: identity[2])
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
70 data.update({
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
71 u'features': features,
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
72 u'identities': identities,
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
73 u'extensions': extensions})
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
74
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
75 if self.get_items:
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
76 items.sort(key=lambda item: item[2])
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
77 data[u'items'] = items
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
78
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
79 self.output(data)
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
80 self.host.quit()
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
81
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
82 def default_output(self, data):
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
83 features = data.get(u'features', [])
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
84 identities = data.get(u'identities', [])
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
85 extensions = data.get(u'extensions', {})
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
86 items = data.get(u'items', [])
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
87
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
88 identities_table = common.Table(self.host,
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
89 identities,
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
90 headers=(_(u'category'),
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
91 _(u'type'),
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
92 _(u'name')),
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
93 use_buffer=True)
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
94
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
95 extensions_tpl = []
1414
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
96 extensions_types = extensions.keys()
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
97 extensions_types.sort()
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
98 for type_ in extensions_types:
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
99 fields = []
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
100 for field in extensions[type_]:
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
101 field_lines = []
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
102 data, values = field
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
103 data_keys = data.keys()
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
104 data_keys.sort()
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
105 for key in data_keys:
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
106 field_lines.append(A.color(u'\t', C.A_SUBHEADER, key, data[key]))
1414
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
107 for value in values:
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
108 field_lines.append(A.color(u'\t', A.BOLD, value))
1414
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
109 fields.append(u'\n'.join(field_lines))
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
110 extensions_tpl.append(u'{type_}\n{fields}'.format(type_=type_,
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
111 fields='\n\n'.join(fields)))
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
112
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
113 items_table = common.Table(self.host,
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
114 items,
2347
b6dee1f66478 jp (info/disco): fixed headers order for items table
Goffi <goffi@goffi.org>
parents: 2346
diff changeset
115 headers=(_(u'entity'),
b6dee1f66478 jp (info/disco): fixed headers order for items table
Goffi <goffi@goffi.org>
parents: 2346
diff changeset
116 _(u'node'),
b6dee1f66478 jp (info/disco): fixed headers order for items table
Goffi <goffi@goffi.org>
parents: 2346
diff changeset
117 _(u'name')),
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
118 use_buffer=True)
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
119
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
120 template = []
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
121 if features:
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
122 template.append(A.color(C.A_HEADER, _(u"Features")) + u"\n\n{features}")
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
123 if identities:
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
124 template.append(A.color(C.A_HEADER, _(u"Identities")) + u"\n\n{identities}")
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
125 if extensions:
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
126 template.append(A.color(C.A_HEADER, _(u"Extensions")) + u"\n\n{extensions}")
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
127 if items:
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
128 template.append(A.color(C.A_HEADER, _(u"Items")) + u"\n\n{items}")
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
129
2346
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
130 print u"\n\n".join(template).format(features = u'\n'.join(features),
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
131 identities = identities_table.display().string,
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
132 extensions = u'\n'.join(extensions_tpl),
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
133 items = items_table.display().string,
c903c259402a jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents: 2343
diff changeset
134 )
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
135
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
136
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
137 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
138
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
139 def __init__(self, host):
2340
4fd499d14b27 jp (info): fixed help for version and session
Goffi <goffi@goffi.org>
parents: 2151
diff changeset
140 super(Version, self).__init__(host, 'version', help=_('software version'))
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
141 self.need_loop=True
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
142
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
143 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
144 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
145
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
146 def start(self):
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
147 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
148 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
149 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
150
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
151 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
152 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
153 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
154
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
155 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
156 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
157 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
158 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
159 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
160 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
161 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
162 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
163 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
164
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
165 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
166 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
167
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
168
2114
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
169 class Session(base.CommandBase):
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
170
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
171 def __init__(self, host):
2600
947c4c4c5c53 jp (info/session): by default, display started as human readable date instead of Unix time
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
172 extra_outputs = {'default': self.default_output}
947c4c4c5c53 jp (info/session): by default, display started as human readable date instead of Unix time
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 super(Session, self).__init__(host, 'session', use_output='dict', extra_outputs=extra_outputs, help=_('running session'))
2114
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
174 self.need_loop=True
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
175
2600
947c4c4c5c53 jp (info/session): by default, display started as human readable date instead of Unix time
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 def default_output(self, data):
947c4c4c5c53 jp (info/session): by default, display started as human readable date instead of Unix time
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 started = data['started']
2605
87f8cf51fca5 jp (info/session): show short + relative date by default for "started"
Goffi <goffi@goffi.org>
parents: 2600
diff changeset
178 data['started'] = u'{short} (UTC, {relative})'.format(
87f8cf51fca5 jp (info/session): show short + relative date by default for "started"
Goffi <goffi@goffi.org>
parents: 2600
diff changeset
179 short=date_utils.date_fmt(started),
87f8cf51fca5 jp (info/session): show short + relative date by default for "started"
Goffi <goffi@goffi.org>
parents: 2600
diff changeset
180 relative=date_utils.date_fmt(started, 'relative'))
2600
947c4c4c5c53 jp (info/session): by default, display started as human readable date instead of Unix time
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 self.host.output(C.OUTPUT_DICT, 'simple', {}, data)
947c4c4c5c53 jp (info/session): by default, display started as human readable date instead of Unix time
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182
2114
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
183 def add_parser_options(self):
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
184 pass
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
185
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
186 def start(self):
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
187 self.host.bridge.sessionInfosGet(self.host.profile, callback=self._sessionInfoGetCb, errback=self._sessionInfoGetEb)
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
188
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
189 def _sessionInfoGetCb(self, data):
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
190 self.output(data)
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
191 self.host.quit()
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
192
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
193 def _sessionInfoGetEb(self, error_data):
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
194 self.disp(_(u'Error getting session infos: {}').format(error_data), error=True)
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
195 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
196
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
197
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
198 class Info(base.CommandBase):
2114
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
199 subcommands = (Disco, Version, Session)
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
200
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
201 def __init__(self, host):
1199
96fb74a4714d misc: fixed some typos
Matteo Cypriani <mcy@lm7.fr>
parents: 1063
diff changeset
202 super(Info, self).__init__(host, 'info', use_profile=False, help=_('Get various pieces of information on entities'))