changeset 3600:1709f0a78f50

jp (base): add flag for `use_pubsub` to add cache skipping option
author Goffi <goffi@goffi.org>
date Thu, 29 Jul 2021 22:51:01 +0200
parents ab1fe6b25631
children b46e9791168f
files sat_frontends/jp/base.py sat_frontends/jp/cmd_blog.py sat_frontends/jp/cmd_pubsub.py sat_frontends/jp/constants.py
diffstat 4 files changed, 22 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/jp/base.py	Thu Jul 29 22:51:01 2021 +0200
+++ b/sat_frontends/jp/base.py	Thu Jul 29 22:51:01 2021 +0200
@@ -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
@@ -332,7 +333,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
@@ -402,7 +403,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
@@ -424,6 +425,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)))
@@ -1235,6 +1242,16 @@
         else:
             if order_by is not None:
                 extra[C.KEY_ORDER_BY] = self.args.order_by
+
+        # 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):
--- a/sat_frontends/jp/cmd_blog.py	Thu Jul 29 22:51:01 2021 +0200
+++ b/sat_frontends/jp/cmd_blog.py	Thu Jul 29 22:51:01 2021 +0200
@@ -251,7 +251,7 @@
             "get",
             use_verbose=True,
             use_pubsub=True,
-            pubsub_flags={C.MULTI_ITEMS},
+            pubsub_flags={C.MULTI_ITEMS, C.CACHE},
             use_output=C.OUTPUT_COMPLEX,
             extra_outputs=extra_outputs,
             help=_("get blog item(s)"),
--- a/sat_frontends/jp/cmd_pubsub.py	Thu Jul 29 22:51:01 2021 +0200
+++ b/sat_frontends/jp/cmd_pubsub.py	Thu Jul 29 22:51:01 2021 +0200
@@ -823,7 +823,7 @@
             "get",
             use_output=C.OUTPUT_LIST_XML,
             use_pubsub=True,
-            pubsub_flags={C.NODE, C.MULTI_ITEMS},
+            pubsub_flags={C.NODE, C.MULTI_ITEMS, C.CACHE},
             help=_("get pubsub item(s)"),
         )
 
@@ -835,7 +835,6 @@
             help=_("subscription id"),
         )
         #  TODO: a key(s) argument to select keys to display
-        # TODO: add MAM filters
 
     async def start(self):
         try:
--- a/sat_frontends/jp/constants.py	Thu Jul 29 22:51:01 2021 +0200
+++ b/sat_frontends/jp/constants.py	Thu Jul 29 22:51:01 2021 +0200
@@ -62,6 +62,7 @@
     SINGLE_ITEM = "single_item"  # only one item is allowed
     MULTI_ITEMS = "multi_items"  # multiple items are allowed
     NO_MAX = "no_max"  # don't add --max option for multi items
+    CACHE = "cache"  # add cache control flag
 
     # ANSI
     A_HEADER = A.BOLD + A.FG_YELLOW