comparison 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
comparison
equal deleted inserted replaced
2801:ae127e14b040 2802:f61a50790fae
159 exit_code=C.EXIT_BRIDGE_ERRBACK, 159 exit_code=C.EXIT_BRIDGE_ERRBACK,
160 ), 160 ),
161 ) 161 )
162 162
163 163
164 class NodePurge(base.CommandBase):
165
166 def __init__(self, host):
167 super(NodePurge, self).__init__(
168 host,
169 "purge",
170 use_pubsub=True,
171 pubsub_flags={C.NODE},
172 help=_(u"purge a node (i.e. remove all items from it)"),
173 )
174 self.need_loop = True
175
176 def add_parser_options(self):
177 self.parser.add_argument(
178 "-f",
179 "--force",
180 action="store_true",
181 help=_(u"purge node without confirmation"),
182 )
183
184 def psNodePurgeCb(self):
185 self.disp(_(u"node [{node}] purged successfully").format(node=self.args.node))
186 self.host.quit()
187
188 def start(self):
189 if not self.args.force:
190 if not self.args.service:
191 message = _(u"Are you sure to purge PEP node [{node_id}]? "
192 u"This will delete ALL items from it!").format(
193 node_id=self.args.node
194 )
195 else:
196 message = _(
197 u"Are you sure to delete node [{node_id}] on service [{service}]? "
198 u"This will delete ALL items from it!"
199 ).format(node_id=self.args.node, service=self.args.service)
200 self.host.confirmOrQuit(message, _(u"node purge cancelled"))
201
202 self.host.bridge.psNodePurge(
203 self.args.service,
204 self.args.node,
205 self.profile,
206 callback=self.psNodePurgeCb,
207 errback=partial(
208 self.errback,
209 msg=_(u"can't purge node: {}"),
210 exit_code=C.EXIT_BRIDGE_ERRBACK,
211 ),
212 )
213
214
164 class NodeDelete(base.CommandBase): 215 class NodeDelete(base.CommandBase):
165 def __init__(self, host): 216 def __init__(self, host):
166 base.CommandBase.__init__( 217 base.CommandBase.__init__(
167 self, 218 self,
168 host, 219 host,
186 self.host.quit() 237 self.host.quit()
187 238
188 def start(self): 239 def start(self):
189 if not self.args.force: 240 if not self.args.force:
190 if not self.args.service: 241 if not self.args.service:
191 message = _(u"Are you sure to delete pep node [{node_id}] ?").format( 242 message = _(u"Are you sure to delete PEP node [{node_id}] ?").format(
192 node_id=self.args.node 243 node_id=self.args.node
193 ) 244 )
194 else: 245 else:
195 message = _( 246 message = _(
196 u"Are you sure to delete node [{node_id}] on service [{service}] ?" 247 u"Are you sure to delete node [{node_id}] on service [{service}] ?"
640 691
641 class Node(base.CommandBase): 692 class Node(base.CommandBase):
642 subcommands = ( 693 subcommands = (
643 NodeInfo, 694 NodeInfo,
644 NodeCreate, 695 NodeCreate,
696 NodePurge,
645 NodeDelete, 697 NodeDelete,
646 NodeSet, 698 NodeSet,
647 NodeAffiliations, 699 NodeAffiliations,
648 NodeSubscriptions, 700 NodeSubscriptions,
649 NodeSchema, 701 NodeSchema,