1# http://pyrocko.org - GPLv3 

2# 

3# The Pyrocko Developers, 21st Century 

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

5 

6from __future__ import absolute_import, print_function 

7 

8 

9guts_prefix = 'squirrel' 

10 

11 

12def make_subparser(subparsers): 

13 return subparsers.add_parser( 

14 'operators', 

15 help='Print available operator mappings.') 

16 

17 

18def setup(parser): 

19 parser.add_squirrel_selection_arguments() 

20 

21 

22def run(parser, args): 

23 squirrel = args.make_squirrel() 

24 

25 def scodes(codes): 

26 css = list(zip(*codes)) 

27 if sum(not all(c == cs[0] for c in cs) for cs in css) == 1: 

28 return '.'.join( 

29 cs[0] if all(c == cs[0] for c in cs) else '(%s)' % ','.join(cs) 

30 for cs in css) 

31 else: 

32 return ', '.join(str(c) for c in codes) 

33 

34 for operator, in_codes, out_codes in squirrel.get_operator_mappings(): 

35 print('%s <- %s <- %s' % ( 

36 scodes(out_codes), operator.name, scodes(in_codes)))