Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/tool/commands/stationxml.py: 26%
23 statements
« prev ^ index » next coverage.py v6.5.0, created at 2024-03-07 11:54 +0000
« 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----------
6'''
7Implementation of :app:`squirrel stationxml`.
8'''
10from pyrocko.squirrel.tool.common import ldq, dq
12headline = 'Export station metadata as StationXML.'
15def make_subparser(subparsers):
16 return subparsers.add_parser(
17 'stationxml',
18 help=headline,
19 description=headline)
22def setup(parser):
23 parser.add_squirrel_selection_arguments()
24 parser.add_squirrel_query_arguments()
26 level_choices = ('network', 'station', 'channel', 'response')
27 level_default = 'response'
29 parser.add_argument(
30 '--level',
31 dest='level',
32 choices=level_choices,
33 default=level_default,
34 help='Set level of detail to be returned. Choices: %s. '
35 'Default: %s.' % (
36 ldq(level_choices),
37 dq(level_default)))
39 on_error_choices = ('raise', 'warn', 'ignore')
40 on_error_default = 'raise'
42 parser.add_argument(
43 '--on-error',
44 dest='on_error',
45 choices=on_error_choices,
46 default=on_error_default,
47 help='How to handle metadata errors. Choices: %s. '
48 'Default: %s.' % (
49 ldq(on_error_choices),
50 dq(on_error_default)))
52 out_format_choices = ('xml', 'yaml')
53 out_format_default = 'xml'
55 parser.add_argument(
56 '--out-format',
57 dest='out_format',
58 choices=out_format_choices,
59 default=out_format_default,
60 help='Set format of output. Choices: %s. '
61 'Default: %s.' % (
62 ldq(out_format_choices),
63 dq(out_format_default)))
66def run(parser, args):
67 squirrel = args.make_squirrel()
69 sx = squirrel.get_stationxml(
70 **args.squirrel_query,
71 level=args.level,
72 on_error=args.on_error)
74 if args.out_format == 'xml':
75 print(sx.dump_xml())
76 elif args.out_format == 'yaml':
77 print(sx.dump())
78 else:
79 assert False