1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6from ..common import ldq
7from pyrocko.squirrel import model
9headline = 'Search indexed contents.'
12def make_subparser(subparsers):
13 return subparsers.add_parser(
14 'nuts',
15 help=headline,
16 description=headline)
19def setup(parser):
20 parser.add_squirrel_selection_arguments()
21 parser.add_squirrel_query_arguments()
23 style_choices = ['index', 'summary', 'yaml']
25 parser.add_argument(
26 '--style',
27 dest='style',
28 choices=style_choices,
29 default='index',
30 help='Set style of presentation. Choices: %s' % ldq(style_choices))
33def run(parser, args):
34 squirrel = args.make_squirrel()
35 for nut in squirrel.iter_nuts(**args.squirrel_query):
36 if args.style == 'index':
37 print(nut.summary)
38 else:
39 cache_id = 'waveform' \
40 if nut.kind_id == model.WAVEFORM \
41 else 'default'
43 content = squirrel.get_content(nut, cache_id=cache_id)
45 if args.style == 'yaml':
46 print('# %s' % nut.summary)
47 print(content.dump())
48 elif args.style == 'summary':
49 print(content.summary)
51 if cache_id == 'waveform':
52 squirrel.clear_accessor(
53 accessor_id='default',
54 cache_id=cache_id)