comparison sat_frontends/jp/cmd_message.py @ 2719:45189c8bd165

jp (message/mam): display metadata when verbose
author Goffi <goffi@goffi.org>
date Mon, 10 Dec 2018 20:34:45 +0100
parents 0b5deb9a35fd
children 8fd8ce5a5855
comparison
equal deleted inserted replaced
2718:bb6adaa580ee 2719:45189c8bd165
22 from sat_frontends.jp.constants import Const as C 22 from sat_frontends.jp.constants import Const as C
23 from sat_frontends.tools import jid 23 from sat_frontends.tools import jid
24 from sat.core.i18n import _ 24 from sat.core.i18n import _
25 from sat.tools.utils import clean_ustr 25 from sat.tools.utils import clean_ustr
26 from sat.tools.common import data_format 26 from sat.tools.common import data_format
27 from sat.tools.common.ansi import ANSI as A
27 from functools import partial 28 from functools import partial
28 29
29 __commands__ = ["Message"] 30 __commands__ = ["Message"]
30 31
31 32
155 156
156 class MAM(base.CommandBase): 157 class MAM(base.CommandBase):
157 158
158 def __init__(self, host): 159 def __init__(self, host):
159 super(MAM, self).__init__( 160 super(MAM, self).__init__(
160 host, "mam", use_output=C.OUTPUT_MESS, help=_(u"query archives using MAM")) 161 host, "mam", use_output=C.OUTPUT_MESS, use_verbose=True, help=_(u"query archives using MAM"))
161 self.need_loop=True 162 self.need_loop=True
162 163
163 def add_parser_options(self): 164 def add_parser_options(self):
164 self.parser.add_argument( 165 self.parser.add_argument(
165 "-s", "--service", type=base.unicode_decoder, default=u"", 166 "-s", "--service", type=base.unicode_decoder, default=u"",
175 help=_(u"retrieve only archives with this jid")) 176 help=_(u"retrieve only archives with this jid"))
176 self.parser.add_argument( 177 self.parser.add_argument(
177 "-M", "--max", dest="rsm_max", type=int, default=20, 178 "-M", "--max", dest="rsm_max", type=int, default=20,
178 help=_(u"maximum number of items to retrieve, using RSM (default: 20))")) 179 help=_(u"maximum number of items to retrieve, using RSM (default: 20))"))
179 180
180 def _sessionInfosGetCb(self, session_info, data): 181 def _sessionInfosGetCb(self, session_info, data, metadata):
181 self.host.own_jid = jid.JID(session_info[u"jid"]) 182 self.host.own_jid = jid.JID(session_info[u"jid"])
182 self.output(data) 183 self.output(data)
184 # FIXME: metadata are not displayed correctly and don't play nice with output
185 # they should be added to output data somehow
186 if self.verbosity:
187 for value in (u"rsm_first", u"rsm_last", u"rsm_index", u"rsm_count",
188 u"mam_complete", u"mam_stable"):
189 if value in metadata:
190 label = value.split(u"_")[1]
191 self.disp(A.color(
192 C.A_HEADER, label, u': ' , A.RESET, metadata[value]))
193
183 self.host.quit() 194 self.host.quit()
184 195
185 def _MAMGetCb(self, result): 196 def _MAMGetCb(self, result):
186 data, profile = result 197 data, metadata, profile = result
187 self.host.bridge.sessionInfosGet(self.profile, 198 self.host.bridge.sessionInfosGet(self.profile,
188 callback=partial(self._sessionInfosGetCb, data=data), errback=self.errback) 199 callback=partial(self._sessionInfosGetCb, data=data, metadata=metadata),
200 errback=self.errback)
189 201
190 def start(self): 202 def start(self):
191 if self.args.mam_start is None: 203 if self.args.mam_start is None:
192 self.args.mam_start = base.date_decoder(u"-1 day") 204 self.args.mam_start = base.date_decoder(u"-1 day")
193 extra = { 205 extra = {