diff sat_frontends/jp/base.py @ 3715:b9718216a1c0 0.9

merge bookmark 0.9
author Goffi <goffi@goffi.org>
date Wed, 01 Dec 2021 16:13:31 +0100
parents 09f5ac48ffe3
children ea204216a505
line wrap: on
line diff
--- a/sat_frontends/jp/base.py	Tue Nov 30 23:31:09 2021 +0100
+++ b/sat_frontends/jp/base.py	Wed Dec 01 16:13:31 2021 +0100
@@ -34,6 +34,7 @@
 import termios
 from pathlib import Path
 from glob import iglob
+from typing import Optional
 from importlib import import_module
 from sat_frontends.tools.jid import JID
 from sat.tools import config
@@ -41,6 +42,7 @@
 from sat.tools.common import uri
 from sat.tools.common import date_utils
 from sat.tools.common import utils
+from sat.tools.common import data_format
 from sat.tools.common.ansi import ANSI as A
 from sat.core import exceptions
 import sat_frontends.jp
@@ -364,7 +366,7 @@
 
 
     def make_pubsub_group(self, flags, defaults):
-        """generate pubsub options according to flags
+        """Generate pubsub options according to flags
 
         @param flags(iterable[unicode]): see [CommandBase.__init__]
         @param defaults(dict[unicode, unicode]): help text for default value
@@ -434,7 +436,7 @@
                 help=_("find page before this item"), metavar='ITEM_ID')
             rsm_page_group.add_argument(
                 "--index", dest="rsm_index", type=int,
-                help=_("index of the page to retrieve"))
+                help=_("index of the first item to retrieve"))
 
 
             # MAM
@@ -456,6 +458,12 @@
                                              C.ORDER_BY_MODIFICATION],
                 help=_("how items should be ordered"))
 
+        if flags[C.CACHE]:
+            pubsub_group.add_argument(
+                "-C", "--no-cache", dest="use_cache", action='store_false',
+                help=_("don't use Pubsub cache")
+            )
+
         if not flags.all_used:
             raise exceptions.InternalError('unknown flags: {flags}'.format(
                 flags=', '.join(flags.unused)))
@@ -1223,11 +1231,11 @@
                 _('trying to use output when use_output has not been set'))
         return self.host.output(output_type, self.args.output, self.extra_outputs, data)
 
-    def getPubsubExtra(self, extra=None):
+    def getPubsubExtra(self, extra: Optional[dict] = None) -> str:
         """Helper method to compute extra data from pubsub arguments
 
-        @param extra(None, dict): base extra dict, or None to generate a new one
-        @return (dict): dict which can be used directly in the bridge for pubsub
+        @param extra: base extra dict, or None to generate a new one
+        @return: dict which can be used directly in the bridge for pubsub
         """
         if extra is None:
             extra = {}
@@ -1268,7 +1276,17 @@
         else:
             if order_by is not None:
                 extra[C.KEY_ORDER_BY] = self.args.order_by
-        return extra
+
+        # Cache
+        try:
+            use_cache = self.args.use_cache
+        except AttributeError:
+            pass
+        else:
+            if not use_cache:
+                extra[C.KEY_USE_CACHE] = use_cache
+
+        return data_format.serialise(extra)
 
     def add_parser_options(self):
         try: