diff --git a/sat_frontends/jp/base.py b/sat_frontends/jp/base.py index f0c0c282..3ea31800 100644 --- a/sat_frontends/jp/base.py +++ b/sat_frontends/jp/base.py @@ -375,6 +375,14 @@ class Jp(object): 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 @@ class CommandBase(object): 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 --git a/sat_frontends/jp/cmd_blog.py b/sat_frontends/jp/cmd_blog.py index 178c534f..9d4bfb21 100644 --- a/sat_frontends/jp/cmd_blog.py +++ b/sat_frontends/jp/cmd_blog.py @@ -393,7 +393,7 @@ class Get(base.CommandBase): self.args.node, self.args.max, self.args.items, - {}, + self.getPubsubExtra(), self.profile, callback=self.mbGetCb, errback=self.mbGetEb, diff --git a/sat_frontends/jp/cmd_pubsub.py b/sat_frontends/jp/cmd_pubsub.py index 8c05b5dc..f97169ed 100644 --- a/sat_frontends/jp/cmd_pubsub.py +++ b/sat_frontends/jp/cmd_pubsub.py @@ -760,7 +760,7 @@ class Get(base.CommandBase): self.args.max, self.args.items, self.args.sub_id, - {}, + self.getPubsubExtra(), self.profile, callback=self.psItemsGetCb, errback=self.psItemsGetEb, @@ -1217,7 +1217,7 @@ class Search(base.CommandBase): self.args.max, items, "", - {}, + self.getPubsubExtra(), self.profile, callback=search, errback=errback, diff --git a/sat_frontends/jp/cmd_ticket.py b/sat_frontends/jp/cmd_ticket.py index ab0d6589..7fca81b8 100644 --- a/sat_frontends/jp/cmd_ticket.py +++ b/sat_frontends/jp/cmd_ticket.py @@ -60,7 +60,7 @@ class Get(base.CommandBase): self.args.max, self.args.items, u"", - {}, + self.getPubsubExtra(), self.profile, callback=self.ticketsGetCb, errback=partial(