Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/tool/commands/dataset.py: 57%
35 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
1import logging
3from pyrocko.util import glob_filter
4from pyrocko import squirrel
5from ..common import SquirrelCommand
7logger = logging.getLogger('psq.cli.dataset')
9headline = 'Dataset managment.'
11description = '''%s
13Get information about built-in datasets.
14''' % headline
17def add_argument_dataset_names(parser, nargs):
18 parser.add_argument(
19 dest='dataset_names',
20 nargs=nargs,
21 metavar='NAMES',
22 help='List only datasets with names matching given (glob-style) '
23 'patterns.')
26def get_matching_builtin_datasets(name_patterns):
27 datasets = squirrel.dataset.get_builtin_datasets()
28 return [
29 (name, datasets[name])
30 for name in sorted(glob_filter(name_patterns, datasets.keys()))]
33class List(SquirrelCommand):
35 def make_subparser(self, subparsers):
36 return subparsers.add_parser(
37 'list',
38 help='List builtin datasets.',
39 description='List builtin datasets.')
41 def setup(self, parser):
42 add_argument_dataset_names(parser, '*')
44 def run(self, parser, args):
45 for (name, ds) in get_matching_builtin_datasets(args.dataset_names):
46 print('%-25s %s' % (name, ds.comment or ''))
49class Show(SquirrelCommand):
51 def make_subparser(self, subparsers):
52 return subparsers.add_parser(
53 'show',
54 help='Print dataset description.',
55 description='Print dataset description.')
57 def setup(self, parser):
58 add_argument_dataset_names(parser, '+')
60 def run(self, parser, args):
61 for (name, ds) in get_matching_builtin_datasets(args.dataset_names):
62 print('# %s' % name)
63 print(ds)
66def make_subparser(subparsers):
67 return subparsers.add_parser(
68 'dataset',
69 help=headline,
70 subcommands=[List(), Show()],
71 description=description)
74def setup(parser):
75 pass
78def run(parser, args):
79 parser.print_help()