diff sat_frontends/jp/cmd_blog.py @ 3866:915fb230cb28

cli (blog, pubsub): new `attachments` subcommands: `pubsub/attachments` subcommands has a `get` and a `set` subcommand to manage attachments of a pubsub item. `blog` has the same subcommands, the only difference is that if `--node` is not specified, the default blog namespace will be used. rel 370
author Goffi <goffi@goffi.org>
date Wed, 20 Jul 2022 17:55:11 +0200
parents 6e785662dd7d
children 5980ea188f87
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_blog.py	Wed Jul 20 17:53:12 2022 +0200
+++ b/sat_frontends/jp/cmd_blog.py	Wed Jul 20 17:55:11 2022 +0200
@@ -27,7 +27,7 @@
 import asyncio
 from asyncio.subprocess import DEVNULL
 from pathlib import Path
-from . import base
+from . import base, cmd_pubsub
 from sat.core.i18n import _
 from sat_frontends.jp.constants import Const as C
 from sat_frontends.jp import common
@@ -1070,12 +1070,63 @@
                     error=True,
                 )
                 self.host.quit(1)
+            else:
+                await self.set_progress_id(progress_id)
 
-            await self.set_progress_id(progress_id)
+
+class AttachmentGet(cmd_pubsub.AttachmentGet):
+
+    def __init__(self, host):
+        super().__init__(host)
+        self.overridePubsubFlags({C.SERVICE, C.SINGLE_ITEM})
+
+
+    async def start(self):
+        if not self.args.node:
+            namespaces = await self.host.bridge.namespacesGet()
+            try:
+                ns_microblog = namespaces["microblog"]
+            except KeyError:
+                self.disp("XEP-0277 plugin is not loaded", error=True)
+                self.host.quit(C.EXIT_MISSING_FEATURE)
+            else:
+                self.args.node = ns_microblog
+        return await super().start()
+
+
+class AttachmentSet(cmd_pubsub.AttachmentSet):
+
+    def __init__(self, host):
+        super().__init__(host)
+        self.overridePubsubFlags({C.SERVICE, C.SINGLE_ITEM})
+
+    async def start(self):
+        if not self.args.node:
+            namespaces = await self.host.bridge.namespacesGet()
+            try:
+                ns_microblog = namespaces["microblog"]
+            except KeyError:
+                self.disp("XEP-0277 plugin is not loaded", error=True)
+                self.host.quit(C.EXIT_MISSING_FEATURE)
+            else:
+                self.args.node = ns_microblog
+        return await super().start()
+
+
+class Attachments(base.CommandBase):
+    subcommands = (AttachmentGet, AttachmentSet)
+
+    def __init__(self, host):
+        super().__init__(
+            host,
+            "attachments",
+            use_profile=False,
+            help=_("set or retrieve blog attachments"),
+        )
 
 
 class Blog(base.CommandBase):
-    subcommands = (Set, Get, Edit, Rename, Repeat, Preview, Import)
+    subcommands = (Set, Get, Edit, Rename, Repeat, Preview, Import, Attachments)
 
     def __init__(self, host):
         super(Blog, self).__init__(