Coverage for /usr/local/lib/python3.11/dist-packages/pyrocko/squirrel/tool/commands/operators.py: 33%
15 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 operators`.
8'''
10guts_prefix = 'squirrel'
13def make_subparser(subparsers):
14 return subparsers.add_parser(
15 'operators',
16 help='Print available operator mappings.')
19def setup(parser):
20 parser.add_squirrel_selection_arguments()
23def run(parser, args):
24 squirrel = args.make_squirrel()
26 def scodes(codes):
27 css = list(zip(*codes))
28 if sum(not all(c == cs[0] for c in cs) for cs in css) == 1:
29 return '.'.join(
30 cs[0] if all(c == cs[0] for c in cs) else '(%s)' % ','.join(cs)
31 for cs in css)
32 else:
33 return ', '.join(str(c) for c in codes)
35 for operator, in_codes, out_codes in squirrel.get_operator_mappings():
36 print('%s <- %s <- %s' % (
37 scodes(out_codes), operator.name, scodes(in_codes)))