Mercurial > libervia-backend
comparison sat_frontends/jp/base.py @ 3715:b9718216a1c0 0.9
merge bookmark 0.9
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 01 Dec 2021 16:13:31 +0100 |
parents | 09f5ac48ffe3 |
children | ea204216a505 |
comparison
equal
deleted
inserted
replaced
3714:af09b5aaa5d7 | 3715:b9718216a1c0 |
---|---|
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 |
42 from sat.tools.common import date_utils | 43 from sat.tools.common import date_utils |
43 from sat.tools.common import utils | 44 from sat.tools.common import utils |
45 from sat.tools.common import data_format | |
44 from sat.tools.common.ansi import ANSI as A | 46 from sat.tools.common.ansi import ANSI as A |
45 from sat.core import exceptions | 47 from sat.core import exceptions |
46 import sat_frontends.jp | 48 import sat_frontends.jp |
47 from sat_frontends.jp.loops import QuitException, getJPLoop | 49 from sat_frontends.jp.loops import QuitException, getJPLoop |
48 from sat_frontends.jp.constants import Const as C | 50 from sat_frontends.jp.constants import Const as C |
362 draft_group.add_argument( | 364 draft_group.add_argument( |
363 "-F", "--draft-path", type=Path, help=_("path to a draft file to retrieve")) | 365 "-F", "--draft-path", type=Path, help=_("path to a draft file to retrieve")) |
364 | 366 |
365 | 367 |
366 def make_pubsub_group(self, flags, defaults): | 368 def make_pubsub_group(self, flags, defaults): |
367 """generate pubsub options according to flags | 369 """Generate pubsub options according to flags |
368 | 370 |
369 @param flags(iterable[unicode]): see [CommandBase.__init__] | 371 @param flags(iterable[unicode]): see [CommandBase.__init__] |
370 @param defaults(dict[unicode, unicode]): help text for default value | 372 @param defaults(dict[unicode, unicode]): help text for default value |
371 key can be "service" or "node" | 373 key can be "service" or "node" |
372 value will be set in " (DEFAULT: {value})", or can be None to remove DEFAULT | 374 value will be set in " (DEFAULT: {value})", or can be None to remove DEFAULT |
432 rsm_page_group.add_argument( | 434 rsm_page_group.add_argument( |
433 "-b", "--before", dest="rsm_before", | 435 "-b", "--before", dest="rsm_before", |
434 help=_("find page before this item"), metavar='ITEM_ID') | 436 help=_("find page before this item"), metavar='ITEM_ID') |
435 rsm_page_group.add_argument( | 437 rsm_page_group.add_argument( |
436 "--index", dest="rsm_index", type=int, | 438 "--index", dest="rsm_index", type=int, |
437 help=_("index of the page to retrieve")) | 439 help=_("index of the first item to retrieve")) |
438 | 440 |
439 | 441 |
440 # MAM | 442 # MAM |
441 | 443 |
442 pubsub_group.add_argument( | 444 pubsub_group.add_argument( |
453 # available) | 455 # available) |
454 pubsub_group.add_argument( | 456 pubsub_group.add_argument( |
455 "-o", "--order-by", choices=[C.ORDER_BY_CREATION, | 457 "-o", "--order-by", choices=[C.ORDER_BY_CREATION, |
456 C.ORDER_BY_MODIFICATION], | 458 C.ORDER_BY_MODIFICATION], |
457 help=_("how items should be ordered")) | 459 help=_("how items should be ordered")) |
460 | |
461 if flags[C.CACHE]: | |
462 pubsub_group.add_argument( | |
463 "-C", "--no-cache", dest="use_cache", action='store_false', | |
464 help=_("don't use Pubsub cache") | |
465 ) | |
458 | 466 |
459 if not flags.all_used: | 467 if not flags.all_used: |
460 raise exceptions.InternalError('unknown flags: {flags}'.format( | 468 raise exceptions.InternalError('unknown flags: {flags}'.format( |
461 flags=', '.join(flags.unused))) | 469 flags=', '.join(flags.unused))) |
462 if defaults: | 470 if defaults: |
1221 except AttributeError: | 1229 except AttributeError: |
1222 raise exceptions.InternalError( | 1230 raise exceptions.InternalError( |
1223 _('trying to use output when use_output has not been set')) | 1231 _('trying to use output when use_output has not been set')) |
1224 return self.host.output(output_type, self.args.output, self.extra_outputs, data) | 1232 return self.host.output(output_type, self.args.output, self.extra_outputs, data) |
1225 | 1233 |
1226 def getPubsubExtra(self, extra=None): | 1234 def getPubsubExtra(self, extra: Optional[dict] = None) -> str: |
1227 """Helper method to compute extra data from pubsub arguments | 1235 """Helper method to compute extra data from pubsub arguments |
1228 | 1236 |
1229 @param extra(None, dict): base extra dict, or None to generate a new one | 1237 @param extra: base extra dict, or None to generate a new one |
1230 @return (dict): dict which can be used directly in the bridge for pubsub | 1238 @return: dict which can be used directly in the bridge for pubsub |
1231 """ | 1239 """ |
1232 if extra is None: | 1240 if extra is None: |
1233 extra = {} | 1241 extra = {} |
1234 else: | 1242 else: |
1235 intersection = {C.KEY_ORDER_BY}.intersection(list(extra.keys())) | 1243 intersection = {C.KEY_ORDER_BY}.intersection(list(extra.keys())) |
1266 except AttributeError: | 1274 except AttributeError: |
1267 pass | 1275 pass |
1268 else: | 1276 else: |
1269 if order_by is not None: | 1277 if order_by is not None: |
1270 extra[C.KEY_ORDER_BY] = self.args.order_by | 1278 extra[C.KEY_ORDER_BY] = self.args.order_by |
1271 return extra | 1279 |
1280 # Cache | |
1281 try: | |
1282 use_cache = self.args.use_cache | |
1283 except AttributeError: | |
1284 pass | |
1285 else: | |
1286 if not use_cache: | |
1287 extra[C.KEY_USE_CACHE] = use_cache | |
1288 | |
1289 return data_format.serialise(extra) | |
1272 | 1290 |
1273 def add_parser_options(self): | 1291 def add_parser_options(self): |
1274 try: | 1292 try: |
1275 subcommands = self.subcommands | 1293 subcommands = self.subcommands |
1276 except AttributeError: | 1294 except AttributeError: |