comparison libervia/cli/cmd_blog.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 121925996ffb
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
84 "author_jid_verified", 84 "author_jid_verified",
85 "content", 85 "content",
86 "content_xhtml", 86 "content_xhtml",
87 "title", 87 "title",
88 "title_xhtml", 88 "title_xhtml",
89 "extra" 89 "extra",
90 ) 90 )
91 OUTPUT_OPT_NO_HEADER = "no-header" 91 OUTPUT_OPT_NO_HEADER = "no-header"
92 RE_ATTACHMENT_METADATA = re.compile(r"^(?P<key>[a-z_]+)=(?P<value>.*)") 92 RE_ATTACHMENT_METADATA = re.compile(r"^(?P<key>[a-z_]+)=(?P<value>.*)")
93 ALLOWER_ATTACH_MD_KEY = ("desc", "media_type", "external") 93 ALLOWER_ATTACH_MD_KEY = ("desc", "media_type", "external")
94 94
128 else: 128 else:
129 parser.error( 129 parser.error(
130 f"invalid number of argument for {', '.join(self.option_strings)}, it " 130 f"invalid number of argument for {', '.join(self.option_strings)}, it "
131 "must have at most 2 arguments." 131 "must have at most 2 arguments."
132 ) 132 )
133 alt_link = {'url': url} 133 alt_link = {"url": url}
134 if media_type is not None: 134 if media_type is not None:
135 alt_link['media_type'] = media_type 135 alt_link["media_type"] = media_type
136 alt_links = getattr(namespace, self.dest) 136 alt_links = getattr(namespace, self.dest)
137 if alt_links is None: 137 if alt_links is None:
138 alt_links = [] 138 alt_links = []
139 setattr(namespace, self.dest, alt_links) 139 setattr(namespace, self.dest, alt_links)
140 alt_links.append(alt_link) 140 alt_links.append(alt_link)
187 self.parser.add_argument( 187 self.parser.add_argument(
188 "-a", 188 "-a",
189 "--attachment", 189 "--attachment",
190 dest="attachments", 190 dest="attachments",
191 nargs="+", 191 nargs="+",
192 help=_( 192 help=_("attachment in the form URL [metadata_name=value]"),
193 "attachment in the form URL [metadata_name=value]" 193 )
194 ) 194
195 ) 195 self.parser.add_argument(
196 196 "--alt-link",
197 self.parser.add_argument(
198 '--alt-link',
199 action=AltLinkAction, 197 action=AltLinkAction,
200 dest="alt_links", 198 dest="alt_links",
201 metavar=('URL', 'MEDIA_TYPE'), 199 metavar=("URL", "MEDIA_TYPE"),
202 help=( 200 help=(
203 "add an alternative link, you can use {service}, {node} and {item} " 201 "add an alternative link, you can use {service}, {node} and {item} "
204 "template values in URL" 202 "template values in URL"
205 ) 203 ),
206 ) 204 )
207 205
208 comments_group = self.parser.add_mutually_exclusive_group() 206 comments_group = self.parser.add_mutually_exclusive_group()
209 comments_group.add_argument( 207 comments_group.add_argument(
210 "-C", 208 "-C",
226 ) 224 )
227 225
228 self.parser.add_argument( 226 self.parser.add_argument(
229 "--no-id-suffix", 227 "--no-id-suffix",
230 action="store_true", 228 action="store_true",
231 help=_("do no add random suffix to friendly ID") 229 help=_("do no add random suffix to friendly ID"),
232 ) 230 )
233 231
234 self.parser.add_argument( 232 self.parser.add_argument(
235 "-S", 233 "-S",
236 "--syntax", 234 "--syntax",
238 ) 236 )
239 self.parser.add_argument( 237 self.parser.add_argument(
240 "-e", 238 "-e",
241 "--encrypt", 239 "--encrypt",
242 action="store_true", 240 action="store_true",
243 help=_("end-to-end encrypt the blog post") 241 help=_("end-to-end encrypt the blog post"),
244 ) 242 )
245 self.parser.add_argument( 243 self.parser.add_argument(
246 "--encrypt-for", 244 "--encrypt-for",
247 metavar="JID", 245 metavar="JID",
248 action="append", 246 action="append",
249 help=_("encrypt a single item for") 247 help=_("encrypt a single item for"),
250 ) 248 )
251 self.parser.add_argument( 249 self.parser.add_argument(
252 "-X", 250 "-X",
253 "--sign", 251 "--sign",
254 action="store_true", 252 action="store_true",
255 help=_("cryptographically sign the blog post") 253 help=_("cryptographically sign the blog post"),
256 ) 254 )
257 255
258 async def set_mb_data_content(self, content, mb_data): 256 async def set_mb_data_content(self, content, mb_data):
259 if self.default_syntax_used: 257 if self.default_syntax_used:
260 # default syntax has been used 258 # default syntax has been used
299 f"invalid metadata key in --attachment: {key!r}" 297 f"invalid metadata key in --attachment: {key!r}"
300 ) 298 )
301 value = m.group("value").strip() 299 value = m.group("value").strip()
302 if key == "external": 300 if key == "external":
303 if not value: 301 if not value:
304 value=True 302 value = True
305 else: 303 else:
306 value = C.bool(value) 304 value = C.bool(value)
307 attachment[key] = value 305 attachment[key] = value
308 if attachment: 306 if attachment:
309 attachments.append(attachment) 307 attachments.append(attachment)
1215 1213
1216 def __init__(self, host): 1214 def __init__(self, host):
1217 super().__init__(host) 1215 super().__init__(host)
1218 self.override_pubsub_flags({C.SERVICE, C.SINGLE_ITEM}) 1216 self.override_pubsub_flags({C.SERVICE, C.SINGLE_ITEM})
1219 1217
1220
1221 async def start(self): 1218 async def start(self):
1222 if not self.args.node: 1219 if not self.args.node:
1223 namespaces = await self.host.bridge.namespaces_get() 1220 namespaces = await self.host.bridge.namespaces_get()
1224 try: 1221 try:
1225 ns_microblog = namespaces["microblog"] 1222 ns_microblog = namespaces["microblog"]