From d10ce3ad7a8b90910348db77fb0b7f08df0c945d Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 29 Jul 2021 22:51:01 +0200 Subject: [PATCH] jp (base): add flag for `use_pubsub` to add cache skipping option --- sat_frontends/jp/base.py | 21 +++++++++++++++++++-- sat_frontends/jp/cmd_blog.py | 2 +- sat_frontends/jp/cmd_pubsub.py | 3 +-- sat_frontends/jp/constants.py | 1 + 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/sat_frontends/jp/base.py b/sat_frontends/jp/base.py index 52f2e945..f35f6c82 100644 --- a/sat_frontends/jp/base.py +++ b/sat_frontends/jp/base.py @@ -34,6 +34,7 @@ import tty 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 @@ class LiberviaCli: 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 @@ class LiberviaCli: 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 @@ class LiberviaCli: 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 @@ class CommandBase(object): 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): diff --git a/sat_frontends/jp/cmd_blog.py b/sat_frontends/jp/cmd_blog.py index 280e5983..f72f3b2b 100644 --- a/sat_frontends/jp/cmd_blog.py +++ b/sat_frontends/jp/cmd_blog.py @@ -251,7 +251,7 @@ class Get(base.CommandBase): "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)"), diff --git a/sat_frontends/jp/cmd_pubsub.py b/sat_frontends/jp/cmd_pubsub.py index 9c051402..a3a3caa9 100644 --- a/sat_frontends/jp/cmd_pubsub.py +++ b/sat_frontends/jp/cmd_pubsub.py @@ -823,7 +823,7 @@ class Get(base.CommandBase): "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 @@ class Get(base.CommandBase): help=_("subscription id"), ) #  TODO: a key(s) argument to select keys to display - # TODO: add MAM filters async def start(self): try: diff --git a/sat_frontends/jp/constants.py b/sat_frontends/jp/constants.py index d3ef06dc..1a2e8927 100644 --- a/sat_frontends/jp/constants.py +++ b/sat_frontends/jp/constants.py @@ -62,6 +62,7 @@ class Const(constants.Const): 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