Mercurial > libervia-backend
diff sat_frontends/jp/base.py @ 2764:92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
- RSM and MAM args arguments have been added to pubsub group, and activated when multiple items are possible
- /!\ --max-items (i.e. pubsub original max) short option has been change for -M, and -m is now used for RSM max
- pubsub/search -m option has been renamed -M for same reason as above
- pubsub/search -o option has been replaced by -k (for keep), to avoid conflict with order-by (and long version is now --node-max)
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 11 Jan 2019 10:18:02 +0100 |
parents | 4b693ea24d5f |
children | 378188abe941 |
line wrap: on
line diff
--- a/sat_frontends/jp/base.py Fri Jan 11 09:48:19 2019 +0100 +++ b/sat_frontends/jp/base.py Fri Jan 11 10:18:02 2019 +0100 @@ -370,19 +370,53 @@ pubsub_group.add_argument("-i", "--item", type=unicode_decoder, help=item_help) pubsub_group.add_argument("-L", "--last-item", action='store_true', help=_(u'retrieve last item')) elif flags.multi_items: - # mutiple items + # mutiple items, this activate several features: max-items, RSM, MAM + # 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, - help=_(u"maximum number of items to get ({no_limit} to get all items)".format(no_limit=C.NO_LIMIT))) - # TODO: order-by should be a list to handle several levels of ordering - # but this is not yet done in SàT (and not really useful with - # current specifications, as only "creation" and "modification" are - # available) pubsub_group.add_argument( - "-o", "--order-by", choices=[C.ORDER_BY_CREATION, - C.ORDER_BY_MODIFICATION], - help=_(u"how items should be ordered")) + "-M", "--max-items", dest="max", type=int, default=10, + help=_(u"maximum number of items to get ({no_limit} to get all items)" + .format(no_limit=C.NO_LIMIT))) + + # 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, + help=_(u"find page after this item"), metavar='ITEM_ID') + rsm_page_group.add_argument( + "-b", "--before", dest="rsm_before", type=unicode_decoder, + help=_(u"find page before this item"), metavar='ITEM_ID') + rsm_page_group.add_argument( + "--index", dest="rsm_index", type=int, + help=_(u"index of the page to retrieve")) + + + # MAM + + pubsub_group.add_argument( + "-f", "--filter", dest='mam_filters', type=unicode_decoder, nargs=2, + action='append', default=[], help=_(u"MAM filters to use"), + metavar=(u"FILTER_NAME", u"VALUE") + ) + + # Order-By + + # TODO: order-by should be a list to handle several levels of ordering + # but this is not yet done in SàT (and not really useful with + # current specifications, as only "creation" and "modification" are + # available) + pubsub_group.add_argument( + "-o", "--order-by", choices=[C.ORDER_BY_CREATION, + C.ORDER_BY_MODIFICATION], + help=_(u"how items should be ordered")) if not flags.all_used: raise exceptions.InternalError('unknown flags: {flags}'.format(flags=u', '.join(flags.unused))) @@ -996,9 +1030,35 @@ if extra is None: extra = {} else: - if {C.KEY_ORDER_BY}.intersection(extra.keys()): - raise exceptions.InternalError( - u"given extra dict has conflicting keys with pubsub keys") + intersection = {C.KEY_ORDER_BY}.intersection(extra.keys()) + if intersection: + raise exceptions.ConflictError( + u"given extra dict has conflicting keys with pubsub keys " + u"{intersection}".format(intersection=intersection)) + + # RSM + + for attribute in (u'max', u'after', u'before', 'index'): + key = u'rsm_' + attribute + if key in extra: + raise exceptions.ConflictError( + u"This key already exists in extra: u{key}".format(key=key)) + value = getattr(self.args, key, None) + if value is not None: + extra[key] = unicode(value) + + # MAM + + if hasattr(self.args, u'mam_filters'): + for key, value in self.args.mam_filters: + key = u'filter_' + key + if key in extra: + raise exceptions.ConflictError( + u"This key already exists in extra: u{key}".format(key=key)) + extra[key] = value + + # Order-By + try: order_by = self.args.order_by except AttributeError: