diff sat_frontends/jp/cmd_pubsub.py @ 2802:f61a50790fae

jp (pubsub/node): added purge command
author Goffi <goffi@goffi.org>
date Fri, 15 Feb 2019 22:13:43 +0100
parents ff1b40823b07
children d4a9a60bc650
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_pubsub.py	Fri Feb 15 22:13:43 2019 +0100
+++ b/sat_frontends/jp/cmd_pubsub.py	Fri Feb 15 22:13:43 2019 +0100
@@ -161,6 +161,57 @@
         )
 
 
+class NodePurge(base.CommandBase):
+
+    def __init__(self, host):
+        super(NodePurge, self).__init__(
+            host,
+            "purge",
+            use_pubsub=True,
+            pubsub_flags={C.NODE},
+            help=_(u"purge a node (i.e. remove all items from it)"),
+        )
+        self.need_loop = True
+
+    def add_parser_options(self):
+        self.parser.add_argument(
+            "-f",
+            "--force",
+            action="store_true",
+            help=_(u"purge node without confirmation"),
+        )
+
+    def psNodePurgeCb(self):
+        self.disp(_(u"node [{node}] purged successfully").format(node=self.args.node))
+        self.host.quit()
+
+    def start(self):
+        if not self.args.force:
+            if not self.args.service:
+                message = _(u"Are you sure to purge PEP node [{node_id}]? "
+                            u"This will delete ALL items from it!").format(
+                    node_id=self.args.node
+                )
+            else:
+                message = _(
+                    u"Are you sure to delete node [{node_id}] on service [{service}]? "
+                    u"This will delete ALL items from it!"
+                ).format(node_id=self.args.node, service=self.args.service)
+            self.host.confirmOrQuit(message, _(u"node purge cancelled"))
+
+        self.host.bridge.psNodePurge(
+            self.args.service,
+            self.args.node,
+            self.profile,
+            callback=self.psNodePurgeCb,
+            errback=partial(
+                self.errback,
+                msg=_(u"can't purge node: {}"),
+                exit_code=C.EXIT_BRIDGE_ERRBACK,
+            ),
+        )
+
+
 class NodeDelete(base.CommandBase):
     def __init__(self, host):
         base.CommandBase.__init__(
@@ -188,7 +239,7 @@
     def start(self):
         if not self.args.force:
             if not self.args.service:
-                message = _(u"Are you sure to delete pep node [{node_id}] ?").format(
+                message = _(u"Are you sure to delete PEP node [{node_id}] ?").format(
                     node_id=self.args.node
                 )
             else:
@@ -642,6 +693,7 @@
     subcommands = (
         NodeInfo,
         NodeCreate,
+        NodePurge,
         NodeDelete,
         NodeSet,
         NodeAffiliations,