# HG changeset patch # User Goffi # Date 1546792797 -3600 # Node ID 4b693ea24d5fb418c7a92575e58ddc54644727d1 # Parent 3480d4fdf83a966eaea408c58d9af154e2faac8c jp (base, pubsub, ticket): handle order-by: --order-by has been added to pubsub group. New getPubsubExtra helper method generate extra dict according to arguments. getPubsubExtra is used for pubsub/get, blog/get and and ticket/get. diff -r 3480d4fdf83a -r 4b693ea24d5f sat_frontends/jp/base.py --- a/sat_frontends/jp/base.py Sun Jan 06 17:36:51 2019 +0100 +++ b/sat_frontends/jp/base.py Sun Jan 06 17:39:57 2019 +0100 @@ -375,6 +375,14 @@ 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")) if not flags.all_used: raise exceptions.InternalError('unknown flags: {flags}'.format(flags=u', '.join(flags.unused))) @@ -979,6 +987,27 @@ self.disp(msg.format(failure_), error=True) self.host.quit(exit_code) + def getPubsubExtra(self, extra=None): + """Helper method to compute extra data from pubsub arguments + + @param extra(None, dict): base extra dict, or None to generate a new one + @return (dict): dict which can be used directly in the bridge for pubsub + """ + 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") + try: + order_by = self.args.order_by + except AttributeError: + pass + else: + if order_by is not None: + extra[C.KEY_ORDER_BY] = self.args.order_by + return extra + def add_parser_options(self): try: subcommands = self.subcommands diff -r 3480d4fdf83a -r 4b693ea24d5f sat_frontends/jp/cmd_blog.py --- a/sat_frontends/jp/cmd_blog.py Sun Jan 06 17:36:51 2019 +0100 +++ b/sat_frontends/jp/cmd_blog.py Sun Jan 06 17:39:57 2019 +0100 @@ -393,7 +393,7 @@ self.args.node, self.args.max, self.args.items, - {}, + self.getPubsubExtra(), self.profile, callback=self.mbGetCb, errback=self.mbGetEb, diff -r 3480d4fdf83a -r 4b693ea24d5f sat_frontends/jp/cmd_pubsub.py --- a/sat_frontends/jp/cmd_pubsub.py Sun Jan 06 17:36:51 2019 +0100 +++ b/sat_frontends/jp/cmd_pubsub.py Sun Jan 06 17:39:57 2019 +0100 @@ -760,7 +760,7 @@ self.args.max, self.args.items, self.args.sub_id, - {}, + self.getPubsubExtra(), self.profile, callback=self.psItemsGetCb, errback=self.psItemsGetEb, @@ -1217,7 +1217,7 @@ self.args.max, items, "", - {}, + self.getPubsubExtra(), self.profile, callback=search, errback=errback, diff -r 3480d4fdf83a -r 4b693ea24d5f sat_frontends/jp/cmd_ticket.py --- a/sat_frontends/jp/cmd_ticket.py Sun Jan 06 17:36:51 2019 +0100 +++ b/sat_frontends/jp/cmd_ticket.py Sun Jan 06 17:39:57 2019 +0100 @@ -60,7 +60,7 @@ self.args.max, self.args.items, u"", - {}, + self.getPubsubExtra(), self.profile, callback=self.ticketsGetCb, errback=partial(