comparison sat_frontends/jp/base.py @ 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 003b8b4b56a7
children b2f323237fce
comparison
equal deleted inserted replaced
2774:95321f233387 2775:2dfd5b1d39df
372 elif flags.multi_items: 372 elif flags.multi_items:
373 # mutiple items, this activate several features: max-items, RSM, MAM 373 # mutiple items, this activate several features: max-items, RSM, MAM
374 # and Orbder-by 374 # and Orbder-by
375 pubsub_group.add_argument("-i", "--item", type=unicode_decoder, action='append', dest='items', default=[], help=_(u"items to retrieve (DEFAULT: all)")) 375 pubsub_group.add_argument("-i", "--item", type=unicode_decoder, action='append', dest='items', default=[], help=_(u"items to retrieve (DEFAULT: all)"))
376 if not flags.no_max: 376 if not flags.no_max:
377 pubsub_group.add_argument( 377 max_group = pubsub_group.add_mutually_exclusive_group()
378 "-M", "--max-items", dest="max", type=int, default=10, 378 # XXX: defaut value for --max-items or --max is set in parse_pubsub_args
379 max_group.add_argument(
380 "-M", "--max-items", dest="max", type=int,
379 help=_(u"maximum number of items to get ({no_limit} to get all items)" 381 help=_(u"maximum number of items to get ({no_limit} to get all items)"
380 .format(no_limit=C.NO_LIMIT))) 382 .format(no_limit=C.NO_LIMIT)))
383 # FIXME: it could be possible to no duplicate max (between pubsub
384 # max-items and RSM max)should not be duplicated, RSM could be
385 # used when available and pubsub max otherwise
386 max_group.add_argument(
387 "-m", "--max", dest="rsm_max", type=int,
388 help=_(u"maximum number of items to get per page (DEFAULT: 10)"))
381 389
382 # RSM 390 # RSM
383 391
384 # FIXME: it could be possible to no duplicate max (between pubsub max-items
385 # and RSM max)should not be duplicated, RSM could be used when
386 # available and pubsub max otherwise
387 pubsub_group.add_argument(
388 "-m", "--max", dest="rsm_max", type=int, default=10,
389 help=_(u"maximum number of items to get per page (DEFAULT: 10)"))
390 rsm_page_group = pubsub_group.add_mutually_exclusive_group() 392 rsm_page_group = pubsub_group.add_mutually_exclusive_group()
391 rsm_page_group.add_argument( 393 rsm_page_group.add_argument(
392 "-a", "--after", dest="rsm_after", type=unicode_decoder, 394 "-a", "--after", dest="rsm_after", type=unicode_decoder,
393 help=_(u"find page after this item"), metavar='ITEM_ID') 395 help=_(u"find page after this item"), metavar='ITEM_ID')
394 rsm_page_group.add_argument( 396 rsm_page_group.add_argument(
592 if self.args.item and self.args.item_last: 594 if self.args.item and self.args.item_last:
593 self.parser.error(_(u"--item and --item-last can't be used at the same time")) 595 self.parser.error(_(u"--item and --item-last can't be used at the same time"))
594 except AttributeError: 596 except AttributeError:
595 pass 597 pass
596 598
599 try:
600 max_items = self.args.max
601 rsm_max = self.args.rsm_max
602 except AttributeError:
603 pass
604 else:
605 # we need to set a default value for max, but we need to know if we want
606 # to use pubsub's max or RSM's max. The later is used if any RSM or MAM
607 # argument is set
608 if max_items is None and rsm_max is None:
609 to_check = ('mam_filters', 'rsm_max', 'rsm_after', 'rsm_before',
610 'rsm_index')
611 if any((getattr(self.args, name) for name in to_check)):
612 # we use RSM
613 self.args.rsm_max = 10
614 else:
615 # we use pubsub without RSM
616 self.args.max = 10
617 if self.args.max is None:
618 self.args.max = C.NO_LIMIT
619
597 def run(self, args=None, namespace=None): 620 def run(self, args=None, namespace=None):
598 self.args = self.parser.parse_args(args, namespace=None) 621 self.args = self.parser.parse_args(args, namespace=None)
599 if self.args._cmd._use_pubsub: 622 if self.args._cmd._use_pubsub:
600 self.parse_pubsub_args() 623 self.parse_pubsub_args()
601 try: 624 try: