Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_info.py @ 2827:9a3b99acad91
plugin XEP-0045: fixed item-not-found exception when creating a room:
MAM was checked on the room itself, this patch changes it by checking the MUC service instead.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 01 Mar 2019 17:32:15 +0100 |
parents | 003b8b4b56a7 |
children | ab2696e34d29 |
rev | line source |
---|---|
1960 | 1 #!/usr/bin/env python2 |
966 | 2 # -*- coding: utf-8 -*- |
3 | |
4 # jp: a SAT command line tool | |
2771 | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
966 | 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 import base | |
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 | 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 | 29 |
30 class Disco(base.CommandBase): | |
31 | |
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 | 36 |
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 | 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 | 46 jids = self.host.check_jids([self.args.jid]) |
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 | 56 |
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 | 62 |
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: |
2710
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
106 field_lines.append(A.color(u'\t', C.A_SUBHEADER, key, A.RESET, u': ', |
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
107 data[key])) |
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
108 if len(values) == 1: |
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
109 field_lines.append(A.color(u'\t', C.A_SUBHEADER, u"value", A.RESET, |
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
110 u': ', values[0] or (A.BOLD + u"UNSET"))) |
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
111 elif len(values) > 1: |
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
112 field_lines.append(A.color(u'\t', C.A_SUBHEADER, u"values", A.RESET, |
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
113 u': ')) |
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
114 |
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
115 for value in values: |
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
116 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
|
117 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
|
118 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
|
119 fields='\n\n'.join(fields))) |
966 | 120 |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
121 items_table = common.Table(self.host, |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
122 items, |
2347
b6dee1f66478
jp (info/disco): fixed headers order for items table
Goffi <goffi@goffi.org>
parents:
2346
diff
changeset
|
123 headers=(_(u'entity'), |
b6dee1f66478
jp (info/disco): fixed headers order for items table
Goffi <goffi@goffi.org>
parents:
2346
diff
changeset
|
124 _(u'node'), |
b6dee1f66478
jp (info/disco): fixed headers order for items table
Goffi <goffi@goffi.org>
parents:
2346
diff
changeset
|
125 _(u'name')), |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
126 use_buffer=True) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
127 |
966 | 128 template = [] |
129 if features: | |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
130 template.append(A.color(C.A_HEADER, _(u"Features")) + u"\n\n{features}") |
966 | 131 if identities: |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
132 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
|
133 if extensions: |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
134 template.append(A.color(C.A_HEADER, _(u"Extensions")) + u"\n\n{extensions}") |
966 | 135 if items: |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
136 template.append(A.color(C.A_HEADER, _(u"Items")) + u"\n\n{items}") |
966 | 137 |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
138 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
|
139 identities = identities_table.display().string, |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
140 extensions = u'\n'.join(extensions_tpl), |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
141 items = items_table.display().string, |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
142 ) |
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
|
143 |
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 |
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 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
|
146 |
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 def __init__(self, host): |
2340
4fd499d14b27
jp (info): fixed help for version and session
Goffi <goffi@goffi.org>
parents:
2151
diff
changeset
|
148 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
|
149 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
|
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 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
|
152 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
|
153 |
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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 |
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 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
|
160 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
|
161 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
|
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 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
|
164 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
|
165 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
|
166 if name: |
2681
263a00e90174
jp (info): replaced "Client" by the more generic "Software"
Goffi <goffi@goffi.org>
parents:
2605
diff
changeset
|
167 infos.append(_("Software name: %s") % name) |
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
|
168 if version: |
2681
263a00e90174
jp (info): replaced "Client" by the more generic "Software"
Goffi <goffi@goffi.org>
parents:
2605
diff
changeset
|
169 infos.append(_("Software version: %s") % version) |
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
|
170 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
|
171 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
|
172 |
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
|
173 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
|
174 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
|
175 |
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
|
176 |
2114
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
177 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
|
178 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
179 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
|
180 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
|
181 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
|
182 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
|
183 |
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
|
184 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
|
185 started = data['started'] |
2605
87f8cf51fca5
jp (info/session): show short + relative date by default for "started"
Goffi <goffi@goffi.org>
parents:
2600
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 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
|
190 |
2114
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
191 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
|
192 pass |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
193 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
194 def start(self): |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
195 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
|
196 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
197 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
|
198 self.output(data) |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
199 self.host.quit() |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
200 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
205 |
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
|
206 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
|
207 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
|
208 |
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
|
209 def __init__(self, host): |
1199 | 210 super(Info, self).__init__(host, 'info', use_profile=False, help=_('Get various pieces of information on entities')) |