Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/tool/commands/nuts.py: 28%

25 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2024-03-07 11:54 +0000

1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

4# ---|P------/S----------~Lg---------- 

5 

6''' 

7Implementation of :app:`squirrel nuts`. 

8''' 

9 

10from ..common import ldq 

11from pyrocko.squirrel import model 

12 

13headline = 'Search indexed contents.' 

14 

15 

16def make_subparser(subparsers): 

17 return subparsers.add_parser( 

18 'nuts', 

19 help=headline, 

20 description=headline) 

21 

22 

23def setup(parser): 

24 parser.add_squirrel_selection_arguments() 

25 parser.add_squirrel_query_arguments() 

26 

27 style_choices = ['index', 'summary', 'yaml'] 

28 

29 parser.add_argument( 

30 '--style', 

31 dest='style', 

32 choices=style_choices, 

33 default='index', 

34 help='Set style of presentation. Choices: %s' % ldq(style_choices)) 

35 

36 

37def run(parser, args): 

38 squirrel = args.make_squirrel() 

39 for nut in squirrel.iter_nuts(**args.squirrel_query): 

40 if args.style == 'index': 

41 print(nut.summary) 

42 else: 

43 cache_id = 'waveform' \ 

44 if nut.kind_id == model.WAVEFORM \ 

45 else 'default' 

46 

47 content = squirrel.get_content(nut, cache_id=cache_id) 

48 

49 if args.style == 'yaml': 

50 print('# %s' % nut.summary) 

51 print(content.dump()) 

52 elif args.style == 'summary': 

53 print(content.summary) 

54 

55 if cache_id == 'waveform': 

56 squirrel.clear_accessor( 

57 accessor_id='default', 

58 cache_id=cache_id)