1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6from __future__ import absolute_import, print_function 

7 

8import re 

9 

10from pyrocko.guts import load_string, dump 

11 

12from .. import common 

13 

14 

15templates = { 

16 'dataset-local': ''' 

17--- !squirrel.Dataset 

18 

19# All file paths referenced below are treated relative to the location of this 

20# configuration file, here we may give a common prefix. E.g. setting it to '..' 

21# if the configuration file is in the sub-directory '${project_root}/config' 

22# allows us to give the paths below relative to '${project_root}'. 

23path_prefix: '.' 

24 

25# Data sources to be added (LocalData, FDSNSource, CatalogSource, ...) 

26sources: 

27- !squirrel.LocalData # This data source is for local files. 

28 

29 # These paths are scanned for waveforms, stations, events. 

30 paths: 

31 - 'catalogs/events.txt' 

32 - 'meta/stations.xml' 

33 - 'data/waveforms' 

34 

35 # Select file format or 'detect' for autodetection. 

36 format: 'detect' 

37''', 

38 

39 'dataset-iris': ''' 

40--- !squirrel.Dataset 

41 

42# All file paths referenced below are treated relative to the location of this 

43# configuration file, here we may give a common prefix. E.g. setting it to '..' 

44# if the configuration file is in the sub-directory '${project_root}/config' 

45# allows us to give the paths below relative to '${project_root}'. 

46path_prefix: '.' 

47 

48# Data sources to be added (LocalData, FDSNSource, CatalogSource, ...) 

49sources: 

50- !squirrel.FDSNSource 

51 

52 site: iris 

53 query_args: 

54 channel: '?H?,?L?' 

55''', 

56} 

57 

58names = sorted(templates.keys()) 

59 

60 

61def setup(subparsers): 

62 p = common.add_parser( 

63 subparsers, 'template', 

64 help='Print config snippets.') 

65 

66 p.add_argument( 

67 'name', 

68 choices=names, 

69 help='Name of template to print (choices: %(choices)s).') 

70 

71 p.add_argument( 

72 '--format', '-f', 

73 choices=['commented', 'normal', 'brief'], 

74 default='normal', 

75 help='Set verbosity level of output YAML (default: %(default)s).') 

76 

77 return p 

78 

79 

80def decomment(s): 

81 out = [] 

82 for line in s.splitlines(): 

83 line = re.sub(r'#.+', '', line) 

84 if line.strip(): 

85 out.append(line) 

86 

87 return '\n'.join(out) 

88 

89 

90def brief(s): 

91 return dump(load_string(s)) 

92 

93 

94def call(parser, args): 

95 

96 func = { 

97 'brief': brief, 

98 'commented': lambda s: s, 

99 'normal': decomment}[args.format] 

100 

101 print(func(templates[args.name]))