changeset 2761:4b693ea24d5f

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.
author Goffi <goffi@goffi.org>
date Sun, 06 Jan 2019 17:39:57 +0100 (2019-01-06)
parents 3480d4fdf83a
children 5a51c7fc74a5
files sat_frontends/jp/base.py sat_frontends/jp/cmd_blog.py sat_frontends/jp/cmd_pubsub.py sat_frontends/jp/cmd_ticket.py
diffstat 4 files changed, 33 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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,
--- 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,
--- 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(