Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_info.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 003b8b4b56a7 |
children | fee60f17ebac |
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 | |
3028 | 20 from . import base |
966 | 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): | |
3028 | 38 self.parser.add_argument("jid", help=_("entity to discover")) |
39 self.parser.add_argument("-t", "--type", type=str, choices=('infos', 'items', 'both'), default='both', help=_("type of data to discover")) | |
40 self.parser.add_argument("-n", "--node", default='', help=_("node to use")) | |
41 self.parser.add_argument("-C", "--no-cache", dest='use_cache', action="store_false", help=_("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): |
3028 | 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({ |
3028 | 71 'features': features, |
72 'identities': identities, | |
73 'extensions': extensions}) | |
2346
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]) |
3028 | 77 data['items'] = items |
2346
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): |
3028 | 83 features = data.get('features', []) |
84 identities = data.get('identities', []) | |
85 extensions = data.get('extensions', {}) | |
86 items = data.get('items', []) | |
2346
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, |
3028 | 90 headers=(_('category'), |
91 _('type'), | |
92 _('name')), | |
2346
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 = [] |
3028 | 96 extensions_types = list(extensions.keys()) |
1414
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 |
3028 | 103 data_keys = list(data.keys()) |
1414
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: |
3028 | 106 field_lines.append(A.color('\t', C.A_SUBHEADER, key, A.RESET, ': ', |
2710
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: |
3028 | 109 field_lines.append(A.color('\t', C.A_SUBHEADER, "value", A.RESET, |
110 ': ', values[0] or (A.BOLD + "UNSET"))) | |
2710
b6e16a89311b
jp (info/disco): better default output for extensions
Goffi <goffi@goffi.org>
parents:
2681
diff
changeset
|
111 elif len(values) > 1: |
3028 | 112 field_lines.append(A.color('\t', C.A_SUBHEADER, "values", A.RESET, |
113 ': ')) | |
2710
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: |
3028 | 116 field_lines.append(A.color('\t - ', A.BOLD, value)) |
117 fields.append('\n'.join(field_lines)) | |
118 extensions_tpl.append('{type_}\n{fields}'.format(type_=type_, | |
1414
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, |
3028 | 123 headers=(_('entity'), |
124 _('node'), | |
125 _('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: | |
3028 | 130 template.append(A.color(C.A_HEADER, _("Features")) + "\n\n{features}") |
966 | 131 if identities: |
3028 | 132 template.append(A.color(C.A_HEADER, _("Identities")) + "\n\n{identities}") |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
133 if extensions: |
3028 | 134 template.append(A.color(C.A_HEADER, _("Extensions")) + "\n\n{extensions}") |
966 | 135 if items: |
3028 | 136 template.append(A.color(C.A_HEADER, _("Items")) + "\n\n{items}") |
966 | 137 |
3028 | 138 print("\n\n".join(template).format(features = '\n'.join(features), |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
139 identities = identities_table.display().string, |
3028 | 140 extensions = '\n'.join(extensions_tpl), |
2346
c903c259402a
jp (info/disco): type selection + output improvments:
Goffi <goffi@goffi.org>
parents:
2343
diff
changeset
|
141 items = items_table.display().string, |
3028 | 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): |
3028 | 160 print((_("Error while trying to get version [%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
|
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 |
3028 | 173 print("\n".join(infos)) |
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
|
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'] |
3028 | 186 data['started'] = '{short} (UTC, {relative})'.format( |
2605
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): |
3028 | 202 self.disp(_('Error getting session infos: {}').format(error_data), error=True) |
2114
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')) |