Mercurial > libervia-backend
annotate frontends/src/jp/cmd_info.py @ 2393:8ed4ac10cb5e
plugin tickets import: create comments nodes with open access/publishing
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 27 Oct 2017 08:35:22 +0200 |
parents | b6dee1f66478 |
children | 8b37a62336c3 |
rev | line source |
---|---|
1960 | 1 #!/usr/bin/env python2 |
966 | 2 # -*- coding: utf-8 -*- |
3 | |
4 # jp: a SAT command line tool | |
1766 | 5 # Copyright (C) 2009-2016 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 |
2114
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
23 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
|
24 from sat_frontends.jp import common |
966 | 25 |
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
|
26 __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
|
27 |
966 | 28 |
29 class Disco(base.CommandBase): | |
30 | |
31 def __init__(self, host): | |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
32 extra_outputs = {'default': self.default_output} |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
33 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
|
34 self.need_loop=True |
966 | 35 |
36 def add_parser_options(self): | |
2151
fff88c33442f
jp (info/disco): added --node argument
Goffi <goffi@goffi.org>
parents:
2114
diff
changeset
|
37 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
|
38 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
|
39 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
|
40 self.parser.add_argument(u"-C", u"--no-cache", dest='use_cache', action="store_false", help=_(u"ignore cache")) |
966 | 41 |
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
|
42 def start(self): |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
43 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
|
44 self.get_items = self.args.type in ('items', 'both') |
966 | 45 jids = self.host.check_jids([self.args.jid]) |
46 jid = jids[0] | |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
47 if not self.get_infos: |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
48 self.gotInfos(None, jid) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
49 else: |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
50 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
|
51 |
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 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
|
53 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
|
54 self.host.quit(1) |
966 | 55 |
56 def gotInfos(self, infos, jid): | |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
57 if not self.get_items: |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
58 self.gotItems(infos, None) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
59 else: |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
60 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 | 61 |
62 def gotItems(self, infos, items): | |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
63 data = {} |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
64 |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
65 if self.get_infos: |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
66 features, identities, extensions = infos |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
67 features.sort() |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
68 identities.sort(key=lambda identity: identity[2]) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
69 data.update({ |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
70 u'features': features, |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
71 u'identities': identities, |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
72 u'extensions': extensions}) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
73 |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
74 if self.get_items: |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
75 items.sort(key=lambda item: item[2]) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
76 data[u'items'] = items |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
77 |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
78 self.output(data) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
79 self.host.quit() |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
80 |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
81 def default_output(self, data): |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
82 features = data.get(u'features', []) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
83 identities = data.get(u'identities', []) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
84 extensions = data.get(u'extensions', {}) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
85 items = data.get(u'items', []) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
86 |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
87 identities_table = common.Table(self.host, |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
88 identities, |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
89 headers=(_(u'category'), |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
90 _(u'type'), |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
91 _(u'name')), |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
92 use_buffer=True) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
93 |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
94 extensions_tpl = [] |
1414
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
95 extensions_types = extensions.keys() |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
96 extensions_types.sort() |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
97 for type_ in extensions_types: |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
98 fields = [] |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
99 for field in extensions[type_]: |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
100 field_lines = [] |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
101 data, values = field |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
102 data_keys = data.keys() |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
103 data_keys.sort() |
159d16336f87
core, bridge, jp: management of service discovery extensions (XEP-0128)
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
104 for key in data_keys: |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
105 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
|
106 for value in values: |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 fields='\n\n'.join(fields))) |
966 | 111 |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
112 items_table = common.Table(self.host, |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
113 items, |
2347
b6dee1f66478
jp (info/disco): fixed headers order for items table
Goffi <goffi@goffi.org>
parents:
2346
diff
changeset
|
114 headers=(_(u'entity'), |
b6dee1f66478
jp (info/disco): fixed headers order for items table
Goffi <goffi@goffi.org>
parents:
2346
diff
changeset
|
115 _(u'node'), |
b6dee1f66478
jp (info/disco): fixed headers order for items table
Goffi <goffi@goffi.org>
parents:
2346
diff
changeset
|
116 _(u'name')), |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
117 use_buffer=True) |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
118 |
966 | 119 template = [] |
120 if features: | |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
121 template.append(A.color(C.A_HEADER, _(u"Features")) + u"\n\n{features}") |
966 | 122 if identities: |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
123 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
|
124 if extensions: |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
125 template.append(A.color(C.A_HEADER, _(u"Extensions")) + u"\n\n{extensions}") |
966 | 126 if items: |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
127 template.append(A.color(C.A_HEADER, _(u"Items")) + u"\n\n{items}") |
966 | 128 |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
129 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
|
130 identities = identities_table.display().string, |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
131 extensions = u'\n'.join(extensions_tpl), |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
132 items = items_table.display().string, |
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
133 ) |
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
|
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 |
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 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
|
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 def __init__(self, host): |
2340
4fd499d14b27
jp (info): fixed help for version and session
Goffi <goffi@goffi.org>
parents:
2151
diff
changeset
|
139 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
|
140 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
|
141 |
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 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
|
143 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
|
144 |
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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 |
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 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
|
151 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
|
152 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
|
153 |
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 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 |
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 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
|
165 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
|
166 |
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 |
2114
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
168 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
|
169 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
170 def __init__(self, host): |
2340
4fd499d14b27
jp (info): fixed help for version and session
Goffi <goffi@goffi.org>
parents:
2151
diff
changeset
|
171 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
|
172 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
|
173 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
174 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
|
175 pass |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
176 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
177 def start(self): |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
178 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
|
179 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
180 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
|
181 self.output(data) |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
182 self.host.quit() |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
183 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 |
dc5d214f0a3b
jp (info/session): added a command to get data on current session
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
188 |
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
|
189 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
|
190 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
|
191 |
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
|
192 def __init__(self, host): |
1199 | 193 super(Info, self).__init__(host, 'info', use_profile=False, help=_('Get various pieces of information on entities')) |