changeset 2775:2dfd5b1d39df

jp (base): fixed default values for --max-items and --max when using pubsub
author Goffi <goffi@goffi.org>
date Sat, 12 Jan 2019 16:50:58 +0100
parents 95321f233387
children 838f53730ce4
files sat_frontends/jp/base.py
diffstat 1 files changed, 31 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/jp/base.py	Sat Jan 12 16:50:13 2019 +0100
+++ b/sat_frontends/jp/base.py	Sat Jan 12 16:50:58 2019 +0100
@@ -374,19 +374,21 @@
             # 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 @@
         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: