Mercurial > libervia-backend
changeset 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 | c4190d5340ab |
children | 378188abe941 |
files | CHANGELOG sat_frontends/jp/base.py sat_frontends/jp/cmd_message.py sat_frontends/jp/cmd_pubsub.py |
diffstat | 4 files changed, 89 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/CHANGELOG Fri Jan 11 09:48:19 2019 +0100 +++ b/CHANGELOG Fri Jan 11 10:18:02 2019 +0100 @@ -40,7 +40,7 @@ - new blog/get command, to retrieve locally XMPP blog - new message/mam command, to check MAM archives (this command may be renamed or merged in an other one in the future) - new pubsub commands, for low level pubsub manipulations - - include pubusb/search command for "grepping" pubsub nodes + - include pubsub/search command for "grepping" pubsub nodes - new invitation commands - new event commands - new uri commands, to parse/build XMPP URI @@ -54,6 +54,7 @@ - new encryption commands, to handle encryption sessions - e2e encryption algorithm can now be requested in jp message/send - better handling of arguments for pubsub related commands + - MAM and RSM arguments for pubsub related commands - improved outputs - new template output, jp can now act as a static site generator - a REPL shell is now available with "jp shell" command
--- 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:
--- a/sat_frontends/jp/cmd_message.py Fri Jan 11 09:48:19 2019 +0100 +++ b/sat_frontends/jp/cmd_message.py Fri Jan 11 10:18:02 2019 +0100 @@ -222,7 +222,7 @@ "-W", "--with", dest="mam_with", type=base.unicode_decoder, help=_(u"retrieve only archives with this jid")) self.parser.add_argument( - "-M", "--max", dest="rsm_max", type=int, default=20, + "-m", "--max", dest="rsm_max", type=int, default=20, help=_(u"maximum number of items to retrieve, using RSM (default: 20))")) def _sessionInfosGetCb(self, session_info, data, metadata):
--- a/sat_frontends/jp/cmd_pubsub.py Fri Jan 11 09:48:19 2019 +0100 +++ b/sat_frontends/jp/cmd_pubsub.py Fri Jan 11 10:18:02 2019 +0100 @@ -1021,12 +1021,19 @@ class Search(base.CommandBase): - """this command to a search without using MAM, i.e. by checking every items if dound by itself, so it may be heavy in resources both for server and client""" + """this command do a search without using MAM + + This commands checks every items it finds by itself, + so it may be heavy in resources both for server and client + """ RE_FLAGS = re.MULTILINE | re.UNICODE EXEC_ACTIONS = (u"exec", u"external") def __init__(self, host): + # FIXME: C.NO_MAX is not needed here, and this can be globally removed from consts + # the only interest is to change the help string, but this can be explained + # extensively in man pages (max is for each node found) base.CommandBase.__init__( self, host, @@ -1067,15 +1074,12 @@ ), ) self.parser.add_argument( - "-m", - "--max", + "-M", + "--node-max", type=int, default=30, - help=_( - u"maximum number of items to get per node ({} to get all items, default: 30)".format( - C.NO_LIMIT - ) - ), + help=_(u"maximum number of items to get per node ({} to get all items, " + u"default: 30)".format( C.NO_LIMIT)), ) self.parser.add_argument( "-N", @@ -1178,7 +1182,7 @@ help=_(u"(don't) use DOTALL option for regex (default: don't use)"), ) flags.add_argument( - "-o", + "-k", "--only-matching", action="append", dest="filters",