1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6from __future__ import absolute_import, print_function
8import re
10from pyrocko.guts import load_string, dump
12from .. import common
15templates = {
16 'dataset-local': '''
17--- !squirrel.Dataset
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: '.'
25# Data sources to be added (LocalData, FDSNSource, CatalogSource, ...)
26sources:
27- !squirrel.LocalData # This data source is for local files.
29 # These paths are scanned for waveforms, stations, events.
30 paths:
31 - 'catalogs/events.txt'
32 - 'meta/stations.xml'
33 - 'data/waveforms'
35 # Select file format or 'detect' for autodetection.
36 format: 'detect'
37''',
39 'dataset-iris': '''
40--- !squirrel.Dataset
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: '.'
48# Data sources to be added (LocalData, FDSNSource, CatalogSource, ...)
49sources:
50- !squirrel.FDSNSource
52 site: iris
53 query_args:
54 channel: '?H?,?L?'
55''',
56}
58names = sorted(templates.keys())
61def setup(subparsers):
62 p = common.add_parser(
63 subparsers, 'template',
64 help='Print config snippets.')
66 p.add_argument(
67 'name',
68 choices=names,
69 help='Name of template to print (choices: %(choices)s).')
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).')
77 return p
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)
87 return '\n'.join(out)
90def brief(s):
91 return dump(load_string(s))
94def call(parser, args):
96 func = {
97 'brief': brief,
98 'commented': lambda s: s,
99 'normal': decomment}[args.format]
101 print(func(templates[args.name]))