Mercurial > libervia-backend
comparison frontends/src/jp/cmd_pubsub.py @ 2281:4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 28 Jun 2017 20:28:58 +0200 |
parents | 4bc9a2c2d6c9 |
children | d5c75be1c8c0 |
comparison
equal
deleted
inserted
replaced
2280:4bc9a2c2d6c9 | 2281:4af1805cc6df |
---|---|
296 self.args.sub_id, | 296 self.args.sub_id, |
297 {}, | 297 {}, |
298 self.profile, | 298 self.profile, |
299 callback=self.psItemsGetCb, | 299 callback=self.psItemsGetCb, |
300 errback=self.psItemsGetEb) | 300 errback=self.psItemsGetEb) |
301 | |
302 class Delete(base.CommandBase): | |
303 | |
304 def __init__(self, host): | |
305 base.CommandBase.__init__(self, host, 'delete', use_pubsub_node_req=True, help=_(u'delete an item')) | |
306 self.need_loop=True | |
307 | |
308 def add_parser_options(self): | |
309 self.parser.add_argument("item", nargs='?', type=base.unicode_decoder, help=_(u"item to delete")) | |
310 self.parser.add_argument("-f", "--force", action='store_true', help=_(u"delete without confirmation")) | |
311 self.parser.add_argument("-n", "--notify", action='store_true', help=_(u"notify deletion")) | |
312 | |
313 def psItemsDeleteCb(self): | |
314 self.disp(_(u'item {item_id} has been deleted').format(item_id=self.args.item)) | |
315 self.host.quit(C.EXIT_OK) | |
316 | |
317 def start(self): | |
318 common.checkURI(self.args) | |
319 if not self.args.item: | |
320 self.parser.error(_(u"You need to specify an item to delete")) | |
321 if not self.args.force: | |
322 message = _(u"Are you sure to delete item {item_id} ?").format(item_id=self.args.item) | |
323 res = raw_input("{} (y/N)? ".format(message)) | |
324 if res not in ("y", "Y"): | |
325 self.disp(_(u"Item deletion cancelled")) | |
326 self.host.quit(2) | |
327 self.host.bridge.psRetractItem( | |
328 self.args.service, | |
329 self.args.node, | |
330 self.args.item, | |
331 self.args.notify, | |
332 self.profile, | |
333 callback=self.psItemsDeleteCb, | |
334 errback=partial(self.errback, | |
335 msg=_(u"can't delete item: {}"), | |
336 exit_code=C.EXIT_BRIDGE_ERRBACK)) | |
301 | 337 |
302 | 338 |
303 class Edit(base.CommandBase, common.BaseEdit): | 339 class Edit(base.CommandBase, common.BaseEdit): |
304 | 340 |
305 def __init__(self, host): | 341 def __init__(self, host): |
409 else: | 445 else: |
410 self.display_uri(None) | 446 self.display_uri(None) |
411 | 447 |
412 | 448 |
413 class Pubsub(base.CommandBase): | 449 class Pubsub(base.CommandBase): |
414 subcommands = (Get, Edit, Node, Affiliations, Uri) | 450 subcommands = (Get, Delete, Edit, Node, Affiliations, Uri) |
415 | 451 |
416 def __init__(self, host): | 452 def __init__(self, host): |
417 super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management')) | 453 super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management')) |