comparison 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
comparison
equal deleted inserted replaced
3865:59fbb66b2923 3866:915fb230cb28
25 import tempfile 25 import tempfile
26 import subprocess 26 import subprocess
27 import asyncio 27 import asyncio
28 from asyncio.subprocess import DEVNULL 28 from asyncio.subprocess import DEVNULL
29 from pathlib import Path 29 from pathlib import Path
30 from . import base 30 from . import base, cmd_pubsub
31 from sat.core.i18n import _ 31 from sat.core.i18n import _
32 from sat_frontends.jp.constants import Const as C 32 from sat_frontends.jp.constants import Const as C
33 from sat_frontends.jp import common 33 from sat_frontends.jp import common
34 from sat.tools.common.ansi import ANSI as A 34 from sat.tools.common.ansi import ANSI as A
35 from sat.tools.common import uri 35 from sat.tools.common import uri
1068 self.disp( 1068 self.disp(
1069 _("Error while trying to import a blog: {e}").format(e=e), 1069 _("Error while trying to import a blog: {e}").format(e=e),
1070 error=True, 1070 error=True,
1071 ) 1071 )
1072 self.host.quit(1) 1072 self.host.quit(1)
1073 1073 else:
1074 await self.set_progress_id(progress_id) 1074 await self.set_progress_id(progress_id)
1075
1076
1077 class AttachmentGet(cmd_pubsub.AttachmentGet):
1078
1079 def __init__(self, host):
1080 super().__init__(host)
1081 self.overridePubsubFlags({C.SERVICE, C.SINGLE_ITEM})
1082
1083
1084 async def start(self):
1085 if not self.args.node:
1086 namespaces = await self.host.bridge.namespacesGet()
1087 try:
1088 ns_microblog = namespaces["microblog"]
1089 except KeyError:
1090 self.disp("XEP-0277 plugin is not loaded", error=True)
1091 self.host.quit(C.EXIT_MISSING_FEATURE)
1092 else:
1093 self.args.node = ns_microblog
1094 return await super().start()
1095
1096
1097 class AttachmentSet(cmd_pubsub.AttachmentSet):
1098
1099 def __init__(self, host):
1100 super().__init__(host)
1101 self.overridePubsubFlags({C.SERVICE, C.SINGLE_ITEM})
1102
1103 async def start(self):
1104 if not self.args.node:
1105 namespaces = await self.host.bridge.namespacesGet()
1106 try:
1107 ns_microblog = namespaces["microblog"]
1108 except KeyError:
1109 self.disp("XEP-0277 plugin is not loaded", error=True)
1110 self.host.quit(C.EXIT_MISSING_FEATURE)
1111 else:
1112 self.args.node = ns_microblog
1113 return await super().start()
1114
1115
1116 class Attachments(base.CommandBase):
1117 subcommands = (AttachmentGet, AttachmentSet)
1118
1119 def __init__(self, host):
1120 super().__init__(
1121 host,
1122 "attachments",
1123 use_profile=False,
1124 help=_("set or retrieve blog attachments"),
1125 )
1075 1126
1076 1127
1077 class Blog(base.CommandBase): 1128 class Blog(base.CommandBase):
1078 subcommands = (Set, Get, Edit, Rename, Repeat, Preview, Import) 1129 subcommands = (Set, Get, Edit, Rename, Repeat, Preview, Import, Attachments)
1079 1130
1080 def __init__(self, host): 1131 def __init__(self, host):
1081 super(Blog, self).__init__( 1132 super(Blog, self).__init__(
1082 host, "blog", use_profile=False, help=_("blog/microblog management") 1133 host, "blog", use_profile=False, help=_("blog/microblog management")
1083 ) 1134 )