1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

# http://pyrocko.org - GPLv3 

# 

# The Pyrocko Developers, 21st Century 

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

 

from __future__ import absolute_import, print_function 

 

import re 

 

from pyrocko.guts import load_string, dump 

 

from .. import common 

 

 

templates = { 

'dataset-local': ''' 

--- !squirrel.Dataset 

 

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

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

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

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

path_prefix: '.' 

 

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

sources: 

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

 

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

paths: 

- 'catalogs/events.txt' 

- 'meta/stations.xml' 

- 'data/waveforms' 

 

# Select file format or 'detect' for autodetection. 

format: 'detect' 

'''} 

 

names = sorted(templates.keys()) 

 

 

def setup(subparsers): 

p = common.add_parser( 

subparsers, 'template', 

help='Print config snippets.') 

 

p.add_argument( 

'name', 

choices=names, 

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

 

p.add_argument( 

'--format', '-f', 

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

default='normal', 

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

 

return p 

 

 

def decomment(s): 

out = [] 

for line in s.splitlines(): 

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

if line: 

out.append(line) 

 

return '\n'.join(out) 

 

 

def brief(s): 

return dump(load_string(s)) 

 

 

def call(parser, args): 

 

func = { 

'brief': brief, 

'commented': lambda s: s, 

'normal': decomment}[args.format] 

 

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