From 0dad9969429899225b00b39c112cb7543272787a Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 12 Jan 2019 16:50:58 +0100 Subject: [PATCH] jp (base): fixed default values for --max-items and --max when using pubsub --- sat_frontends/jp/base.py | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/sat_frontends/jp/base.py b/sat_frontends/jp/base.py index 8518f6fe..cc7a9be7 100644 --- a/sat_frontends/jp/base.py +++ b/sat_frontends/jp/base.py @@ -374,19 +374,21 @@ class Jp(object): # and Orbder-by pubsub_group.add_argument("-i", "--item", type=unicode_decoder, action='append', dest='items', default=[], help=_(u"items to retrieve (DEFAULT: all)")) if not flags.no_max: - pubsub_group.add_argument( - "-M", "--max-items", dest="max", type=int, default=10, + max_group = pubsub_group.add_mutually_exclusive_group() + # XXX: defaut value for --max-items or --max is set in parse_pubsub_args + max_group.add_argument( + "-M", "--max-items", dest="max", type=int, help=_(u"maximum number of items to get ({no_limit} to get all items)" .format(no_limit=C.NO_LIMIT))) + # FIXME: it could be possible to no duplicate max (between pubsub + # max-items and RSM max)should not be duplicated, RSM could be + # used when available and pubsub max otherwise + max_group.add_argument( + "-m", "--max", dest="rsm_max", type=int, + help=_(u"maximum number of items to get per page (DEFAULT: 10)")) # RSM - # FIXME: it could be possible to no duplicate max (between pubsub max-items - # and RSM max)should not be duplicated, RSM could be used when - # available and pubsub max otherwise - pubsub_group.add_argument( - "-m", "--max", dest="rsm_max", type=int, default=10, - help=_(u"maximum number of items to get per page (DEFAULT: 10)")) rsm_page_group = pubsub_group.add_mutually_exclusive_group() rsm_page_group.add_argument( "-a", "--after", dest="rsm_after", type=unicode_decoder, @@ -594,6 +596,27 @@ class Jp(object): except AttributeError: pass + try: + max_items = self.args.max + rsm_max = self.args.rsm_max + except AttributeError: + pass + else: + # we need to set a default value for max, but we need to know if we want + # to use pubsub's max or RSM's max. The later is used if any RSM or MAM + # argument is set + if max_items is None and rsm_max is None: + to_check = ('mam_filters', 'rsm_max', 'rsm_after', 'rsm_before', + 'rsm_index') + if any((getattr(self.args, name) for name in to_check)): + # we use RSM + self.args.rsm_max = 10 + else: + # we use pubsub without RSM + self.args.max = 10 + if self.args.max is None: + self.args.max = C.NO_LIMIT + def run(self, args=None, namespace=None): self.args = self.parser.parse_args(args, namespace=None) if self.args._cmd._use_pubsub: