Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/tool/commands/check.py: 33%
24 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-04 09:52 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-04 09:52 +0000
1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6'''
7Implementation of :app:`squirrel check`.
8'''
10import sys
12from pyrocko.squirrel.check import do_check, SquirrelCheckProblemType
14from ..common import csvtype, dq, ldq
16headline = 'Check dataset consistency.'
19def make_subparser(subparsers):
20 return subparsers.add_parser(
21 'check',
22 help=headline,
23 description=headline + '''
25A report listing potential dataset/metadata problems for a given data
26collection is printed to standard output. The following problems are detected:
28%s
29''' % '\n'.join(
30 ' [%s]: %s' % (k, v)
31 for (k, v) in SquirrelCheckProblemType.types.items()))
34def setup(parser):
35 parser.add_squirrel_selection_arguments()
36 parser.add_squirrel_query_arguments(without=['kinds'])
37 parser.add_argument(
38 '--ignore',
39 type=csvtype(SquirrelCheckProblemType.choices),
40 metavar='TYPE,...',
41 help='Problem types to be ignored. Choices: %s.'
42 % ldq(SquirrelCheckProblemType.choices))
44 parser.add_argument(
45 '--verbose', '-v',
46 action='count',
47 dest='verbosity',
48 default=0,
49 help='Verbose mode for textual output. Multiple ``-v`` options '
50 'increase the verbosity. The maximum is 2. At level 1, ``ok`` '
51 'indicators are printed for entries with no problem. At level 2, '
52 'availability information is shown for each entry.')
54 format_default = 'text'
55 format_choices = ['text', 'yaml']
57 parser.add_argument(
58 '--out-format',
59 choices=format_choices,
60 default=format_default,
61 dest='output_format',
62 metavar='FMT',
63 help='Specifies how output is presented. Choices: %s. '
64 'Default: %s.' % (ldq(format_choices), dq(format_default)))
67def run(parser, args):
68 squirrel = args.make_squirrel()
70 check = do_check(
71 squirrel,
72 ignore=args.ignore or [],
73 **args.squirrel_query)
75 if args.output_format == 'text':
76 print(check.get_text(verbosity=args.verbosity))
77 elif args.output_format == 'yaml':
78 print(check)
79 else:
80 assert False
82 sys.exit(0 if check.get_nproblems() == 0 else 1)