From fb01bd4bcca1e5be82dc46dd378d10af54dea073 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 1 May 2021 18:39:34 +0200 Subject: [PATCH] jp (pubsub, blog): `rename` commands implementation --- sat_frontends/jp/cmd_blog.py | 38 +++++++++++++++++++++++++++++++++- sat_frontends/jp/cmd_pubsub.py | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/sat_frontends/jp/cmd_blog.py b/sat_frontends/jp/cmd_blog.py index dd01c0cb..79d8c689 100644 --- a/sat_frontends/jp/cmd_blog.py +++ b/sat_frontends/jp/cmd_blog.py @@ -637,6 +637,42 @@ class Edit(base.CommandBase, BlogPublishCommon, common.BaseEdit): self.host.quit() +class Rename(base.CommandBase): + + def __init__(self, host): + base.CommandBase.__init__( + self, + host, + "rename", + use_pubsub=True, + pubsub_flags={C.SINGLE_ITEM}, + help=_("rename an blog item"), + ) + + def add_parser_options(self): + self.parser.add_argument( + "new_id", + help=_("new item id to use") + ) + + async def start(self): + try: + await self.host.bridge.mbRename( + self.args.service, + self.args.node, + self.args.item, + self.args.new_id, + self.profile, + ) + except Exception as e: + self.disp( + f"can't rename item: {e}", error=True + ) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) + else: + self.disp("Item renamed") + self.host.quit(C.EXIT_OK) + class Preview(base.CommandBase, common.BaseEdit): # TODO: need to be rewritten with template output @@ -994,7 +1030,7 @@ class Import(base.CommandBase): await self.set_progress_id(progress_id) class Blog(base.CommandBase): - subcommands = (Set, Get, Edit, Preview, Import) + subcommands = (Set, Get, Edit, Rename, Preview, Import) def __init__(self, host): super(Blog, self).__init__( diff --git a/sat_frontends/jp/cmd_pubsub.py b/sat_frontends/jp/cmd_pubsub.py index 50d08878..f98fc514 100644 --- a/sat_frontends/jp/cmd_pubsub.py +++ b/sat_frontends/jp/cmd_pubsub.py @@ -960,6 +960,43 @@ class Edit(base.CommandBase, common.BaseEdit): self.host.quit() +class Rename(base.CommandBase): + + def __init__(self, host): + base.CommandBase.__init__( + self, + host, + "rename", + use_pubsub=True, + pubsub_flags={C.NODE, C.SINGLE_ITEM}, + help=_("rename a pubsub item"), + ) + + def add_parser_options(self): + self.parser.add_argument( + "new_id", + help=_("new item id to use") + ) + + async def start(self): + try: + await self.host.bridge.psItemRename( + self.args.service, + self.args.node, + self.args.item, + self.args.new_id, + self.profile, + ) + except Exception as e: + self.disp( + f"can't rename item: {e}", error=True + ) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) + else: + self.disp("Item renamed") + self.host.quit(C.EXIT_OK) + + class Subscribe(base.CommandBase): def __init__(self, host): base.CommandBase.__init__( @@ -1982,6 +2019,7 @@ class Pubsub(base.CommandBase): Get, Delete, Edit, + Rename, Subscribe, Unsubscribe, Subscriptions,