diff frontends/src/jp/cmd_pubsub.py @ 2191:a1a8233f89e8

jp(pubsub/get): pubsub/get command, first draft
author Goffi <goffi@goffi.org>
date Sun, 12 Mar 2017 23:34:51 +0100
parents
children d65275ac39b3
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/frontends/src/jp/cmd_pubsub.py	Sun Mar 12 23:34:51 2017 +0100
@@ -0,0 +1,73 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# jp: a SàT command line tool
+# Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+import base
+from sat.core.i18n import _
+from sat_frontends.jp.constants import Const as C
+
+__commands__ = ["Pubsub"]
+
+
+class Get(base.CommandBase):
+
+    def __init__(self, host):
+        base.CommandBase.__init__(self, host, 'get', use_verbose=True, use_output=C.OUTPUT_LIST_XML, help=_(u'get pubsub item(s)'))
+        self.need_loop=True
+
+    def add_parser_options(self):
+        self.parser.add_argument("-i", "--item", type=base.unicode_decoder, action='append', default=[], dest='items',
+                                 help=_(u"item(s) id(s) to get (default: request all items)"))
+        self.parser.add_argument("-s", "--sub-id", type=base.unicode_decoder, default=u'',
+                                 help=_(u"subscription id"))
+        self.parser.add_argument("-m", "--max", type=int, default=10, help=_(u"maximum number of items to get ({} to get all items)".format(C.NO_LIMIT)))
+        # TODO: a key(s) argument to select keys to display
+        self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request"))
+        self.parser.add_argument("service", type=base.unicode_decoder, nargs='?', default=u'',
+                                 help=_(u"JID of the PubSub service (default: request profile own pubsub)"))
+        # TODO: add MAM filters
+
+
+    def psGetCb(self, ps_result):
+        self.output(ps_result[0])
+        self.host.quit(C.EXIT_OK)
+
+    def psGetEb(self, failure_):
+        self.disp(u"can't get pubsub items: {reason}".format(
+            reason=failure_), error=True)
+        self.host.quit(C.EXIT_BRIDGE_ERRBACK)
+
+    def start(self):
+        self.host.bridge.psGet(
+            self.args.service,
+            self.args.node,
+            self.args.max,
+            self.args.items,
+            self.args.sub_id,
+            {},
+            self.profile,
+            callback=self.psGetCb,
+            errback=self.psGetEb)
+
+
+class Pubsub(base.CommandBase):
+    subcommands = (Get,)
+
+    def __init__(self, host):
+        super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management'))