comparison sat_frontends/jp/cmd_blog.py @ 3521:62f490eff51c

jp (pubsub, blog): `rename` commands implementation
author Goffi <goffi@goffi.org>
date Sat, 01 May 2021 18:39:34 +0200
parents 8acaf857cd0a
children 04283582966f
comparison
equal deleted inserted replaced
3520:8acaf857cd0a 3521:62f490eff51c
634 content_file_obj, mb_data,) = await self.getItemPath() 634 content_file_obj, mb_data,) = await self.getItemPath()
635 635
636 await self.edit(content_file_path, content_file_obj, mb_data=mb_data) 636 await self.edit(content_file_path, content_file_obj, mb_data=mb_data)
637 self.host.quit() 637 self.host.quit()
638 638
639
640 class Rename(base.CommandBase):
641
642 def __init__(self, host):
643 base.CommandBase.__init__(
644 self,
645 host,
646 "rename",
647 use_pubsub=True,
648 pubsub_flags={C.SINGLE_ITEM},
649 help=_("rename an blog item"),
650 )
651
652 def add_parser_options(self):
653 self.parser.add_argument(
654 "new_id",
655 help=_("new item id to use")
656 )
657
658 async def start(self):
659 try:
660 await self.host.bridge.mbRename(
661 self.args.service,
662 self.args.node,
663 self.args.item,
664 self.args.new_id,
665 self.profile,
666 )
667 except Exception as e:
668 self.disp(
669 f"can't rename item: {e}", error=True
670 )
671 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
672 else:
673 self.disp("Item renamed")
674 self.host.quit(C.EXIT_OK)
639 675
640 class Preview(base.CommandBase, common.BaseEdit): 676 class Preview(base.CommandBase, common.BaseEdit):
641 # TODO: need to be rewritten with template output 677 # TODO: need to be rewritten with template output
642 678
643 def __init__(self, host): 679 def __init__(self, host):
992 self.host.quit(1) 1028 self.host.quit(1)
993 1029
994 await self.set_progress_id(progress_id) 1030 await self.set_progress_id(progress_id)
995 1031
996 class Blog(base.CommandBase): 1032 class Blog(base.CommandBase):
997 subcommands = (Set, Get, Edit, Preview, Import) 1033 subcommands = (Set, Get, Edit, Rename, Preview, Import)
998 1034
999 def __init__(self, host): 1035 def __init__(self, host):
1000 super(Blog, self).__init__( 1036 super(Blog, self).__init__(
1001 host, "blog", use_profile=False, help=_("blog/microblog management") 1037 host, "blog", use_profile=False, help=_("blog/microblog management")
1002 ) 1038 )