changeset 2719:45189c8bd165

jp (message/mam): display metadata when verbose
author Goffi <goffi@goffi.org>
date Mon, 10 Dec 2018 20:34:45 +0100
parents bb6adaa580ee
children 453a12ff6f51
files sat_frontends/jp/cmd_message.py
diffstat 1 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_message.py	Mon Dec 10 20:34:45 2018 +0100
+++ b/sat_frontends/jp/cmd_message.py	Mon Dec 10 20:34:45 2018 +0100
@@ -24,6 +24,7 @@
 from sat.core.i18n import _
 from sat.tools.utils import clean_ustr
 from sat.tools.common import data_format
+from sat.tools.common.ansi import ANSI as A
 from functools import partial
 
 __commands__ = ["Message"]
@@ -157,7 +158,7 @@
 
     def __init__(self, host):
         super(MAM, self).__init__(
-            host, "mam", use_output=C.OUTPUT_MESS, help=_(u"query archives using MAM"))
+            host, "mam", use_output=C.OUTPUT_MESS, use_verbose=True, help=_(u"query archives using MAM"))
         self.need_loop=True
 
     def add_parser_options(self):
@@ -177,15 +178,26 @@
             "-M", "--max", dest="rsm_max", type=int, default=20,
             help=_(u"maximum number of items to retrieve, using RSM (default: 20))"))
 
-    def _sessionInfosGetCb(self, session_info, data):
+    def _sessionInfosGetCb(self, session_info, data, metadata):
         self.host.own_jid = jid.JID(session_info[u"jid"])
         self.output(data)
+        # FIXME: metadata are not displayed correctly and don't play nice with output
+        #        they should be added to output data somehow
+        if self.verbosity:
+            for value in (u"rsm_first", u"rsm_last", u"rsm_index", u"rsm_count",
+                          u"mam_complete", u"mam_stable"):
+                if value in metadata:
+                    label = value.split(u"_")[1]
+                    self.disp(A.color(
+                        C.A_HEADER, label, u': ' , A.RESET, metadata[value]))
+
         self.host.quit()
 
     def _MAMGetCb(self, result):
-        data, profile = result
+        data, metadata, profile = result
         self.host.bridge.sessionInfosGet(self.profile,
-            callback=partial(self._sessionInfosGetCb, data=data), errback=self.errback)
+            callback=partial(self._sessionInfosGetCb, data=data, metadata=metadata),
+            errback=self.errback)
 
     def start(self):
         if self.args.mam_start is None: