annotate frontends/src/jp/cmd_info.py @ 2343:ca1ab42c7ae9

jp (info/disco): added --no-cache option
author Goffi <goffi@goffi.org>
date Tue, 22 Aug 2017 22:13:22 +0200
parents 4fd499d14b27
children c903c259402a
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
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1414
diff changeset
5 # Copyright (C) 2009-2016 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 _
2114
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
22 from sat_frontends.jp.constants import Const as C
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
23
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
24 __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
25
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
26
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
27 class Disco(base.CommandBase):
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
28
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
29 def __init__(self, host):
2114
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
30 super(Disco, self).__init__(host, 'disco', 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
31 self.need_loop=True
966
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):
2151
fff88c33442f jp (info/disco): added --node argument
Goffi <goffi@goffi.org>
parents: 2114
diff changeset
34 self.parser.add_argument(u"jid", type=base.unicode_decoder, help=_(u"entity to discover"))
fff88c33442f jp (info/disco): added --node argument
Goffi <goffi@goffi.org>
parents: 2114
diff changeset
35 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
36 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
37
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
38 def start(self):
966
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]
2343
ca1ab42c7ae9 jp (info/disco): added --no-cache option
Goffi <goffi@goffi.org>
parents: 2340
diff changeset
41 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
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):
1063
6ec513ad92c2 frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents: 974
diff changeset
44 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
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):
2343
ca1ab42c7ae9 jp (info/disco): added --no-cache option
Goffi <goffi@goffi.org>
parents: 2340
diff changeset
48 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
49
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
50 def gotItems(self, infos, items):
1414
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
51 features, identities, extensions = infos
966
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
1414
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
59 identities_lst.append(u"{name}({cat}/{type_})".format(
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
60 name = (name+' ') if name else '',
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
61 cat = category,
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
62 type_ = type_))
966
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
1414
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
65 items_lst.append(u"{name}[{entity}{node_id}]".format(
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
66 name = (name+' ') if name else '',
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
67 entity = entity,
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
68 node_id = (', ' + node_id) if node_id else ''
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
69 ))
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
70 extensions_types = extensions.keys()
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
71 extensions_types.sort()
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
72
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
73 extensions_tpl = []
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
74 for type_ in extensions_types:
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
75 fields = []
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
76 for field in extensions[type_]:
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
77 field_lines = []
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
78 data, values = field
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
79 data_keys = data.keys()
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
80 data_keys.sort()
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
81 for key in data_keys:
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
82 field_lines.append(u'\t{key} = {value}'.format(key=key, value=data[key]))
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
83 for value in values:
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
84 field_lines.append(u'\tvalue = {value}'.format(value=value))
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
85 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
86 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
87 fields='\n\n'.join(fields)))
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
88
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
89 template = []
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
90 if features:
1414
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
91 template.append(_(u"Features:\n\n{features}"))
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
92 if identities:
1414
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
93 template.append(_(u"Identities:\n\n{identities}"))
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
94 if extensions_tpl:
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
95 template.append(_(u'Extensions:\n\n{extensions}'))
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
96 if items:
1414
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
97 template.append(_(u"Items:\n\n{items}"))
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
98
1414
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
99 print "\n--\n".join(template).format ( features = '\n'.join(features),
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
100 identities = '\n'.join(identities_lst),
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
101 extensions = '\n'.join(extensions_tpl),
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
102 items = '\n'.join(items_lst),
159d16336f87 core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
103 )
966
9cae72da1b95 jp: added disco subcommand
Goffi <goffi@goffi.org>
parents:
diff changeset
104 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
105
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
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 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
108
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 def __init__(self, host):
2340
4fd499d14b27 jp (info): fixed help for version and session
Goffi <goffi@goffi.org>
parents: 2151
diff changeset
110 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
111 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
112
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 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
114 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
115
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
116 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
117 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
118 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
119 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
120
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 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
122 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
123 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
124
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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134
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 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
136 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
137
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
2114
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
139 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
140
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
141 def __init__(self, host):
2340
4fd499d14b27 jp (info): fixed help for version and session
Goffi <goffi@goffi.org>
parents: 2151
diff changeset
142 super(Session, self).__init__(host, 'session', use_output='dict', 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
143 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
144
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
145 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
146 pass
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
147
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
148 def start(self):
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
149 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
150
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
151 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
152 self.output(data)
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
153 self.host.quit()
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
154
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
155 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
156 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
157 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
158
dc5d214f0a3b jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
159
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
160 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
161 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
162
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 def __init__(self, host):
1199
96fb74a4714d misc: fixed some typos
Matteo Cypriani <mcy@lm7.fr>
parents: 1063
diff changeset
164 super(Info, self).__init__(host, 'info', use_profile=False, help=_('Get various pieces of information on entities'))