comparison sat_frontends/jp/base.py @ 3600:1709f0a78f50

jp (base): add flag for `use_pubsub` to add cache skipping option
author Goffi <goffi@goffi.org>
date Thu, 29 Jul 2021 22:51:01 +0200
parents 5f65f4e9f8cb
children 51983c55c5b6
comparison
equal deleted inserted replaced
3599:ab1fe6b25631 3600:1709f0a78f50
32 import inspect 32 import inspect
33 import tty 33 import tty
34 import termios 34 import termios
35 from pathlib import Path 35 from pathlib import Path
36 from glob import iglob 36 from glob import iglob
37 from typing import Optional
37 from importlib import import_module 38 from importlib import import_module
38 from sat_frontends.tools.jid import JID 39 from sat_frontends.tools.jid import JID
39 from sat.tools import config 40 from sat.tools import config
40 from sat.tools.common import dynamic_import 41 from sat.tools.common import dynamic_import
41 from sat.tools.common import uri 42 from sat.tools.common import uri
330 draft_group.add_argument( 331 draft_group.add_argument(
331 "-F", "--draft-path", type=Path, help=_("path to a draft file to retrieve")) 332 "-F", "--draft-path", type=Path, help=_("path to a draft file to retrieve"))
332 333
333 334
334 def make_pubsub_group(self, flags, defaults): 335 def make_pubsub_group(self, flags, defaults):
335 """generate pubsub options according to flags 336 """Generate pubsub options according to flags
336 337
337 @param flags(iterable[unicode]): see [CommandBase.__init__] 338 @param flags(iterable[unicode]): see [CommandBase.__init__]
338 @param defaults(dict[unicode, unicode]): help text for default value 339 @param defaults(dict[unicode, unicode]): help text for default value
339 key can be "service" or "node" 340 key can be "service" or "node"
340 value will be set in " (DEFAULT: {value})", or can be None to remove DEFAULT 341 value will be set in " (DEFAULT: {value})", or can be None to remove DEFAULT
400 rsm_page_group.add_argument( 401 rsm_page_group.add_argument(
401 "-b", "--before", dest="rsm_before", 402 "-b", "--before", dest="rsm_before",
402 help=_("find page before this item"), metavar='ITEM_ID') 403 help=_("find page before this item"), metavar='ITEM_ID')
403 rsm_page_group.add_argument( 404 rsm_page_group.add_argument(
404 "--index", dest="rsm_index", type=int, 405 "--index", dest="rsm_index", type=int,
405 help=_("index of the page to retrieve")) 406 help=_("index of the first item to retrieve"))
406 407
407 408
408 # MAM 409 # MAM
409 410
410 pubsub_group.add_argument( 411 pubsub_group.add_argument(
421 # available) 422 # available)
422 pubsub_group.add_argument( 423 pubsub_group.add_argument(
423 "-o", "--order-by", choices=[C.ORDER_BY_CREATION, 424 "-o", "--order-by", choices=[C.ORDER_BY_CREATION,
424 C.ORDER_BY_MODIFICATION], 425 C.ORDER_BY_MODIFICATION],
425 help=_("how items should be ordered")) 426 help=_("how items should be ordered"))
427
428 if flags[C.CACHE]:
429 pubsub_group.add_argument(
430 "-C", "--no-cache", dest="use_cache", action='store_false',
431 help=_("don't use Pubsub cache")
432 )
426 433
427 if not flags.all_used: 434 if not flags.all_used:
428 raise exceptions.InternalError('unknown flags: {flags}'.format( 435 raise exceptions.InternalError('unknown flags: {flags}'.format(
429 flags=', '.join(flags.unused))) 436 flags=', '.join(flags.unused)))
430 if defaults: 437 if defaults:
1233 except AttributeError: 1240 except AttributeError:
1234 pass 1241 pass
1235 else: 1242 else:
1236 if order_by is not None: 1243 if order_by is not None:
1237 extra[C.KEY_ORDER_BY] = self.args.order_by 1244 extra[C.KEY_ORDER_BY] = self.args.order_by
1245
1246 # Cache
1247 try:
1248 use_cache = self.args.use_cache
1249 except AttributeError:
1250 pass
1251 else:
1252 if not use_cache:
1253 extra[C.KEY_USE_CACHE] = use_cache
1254
1238 return data_format.serialise(extra) 1255 return data_format.serialise(extra)
1239 1256
1240 def add_parser_options(self): 1257 def add_parser_options(self):
1241 try: 1258 try:
1242 subcommands = self.subcommands 1259 subcommands = self.subcommands