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 

8from .. import common 

9from pyrocko.squirrel.model import separator 

10 

11 

12guts_prefix = 'squirrel' 

13 

14 

15def setup(subparsers): 

16 p = common.add_parser( 

17 subparsers, 'operators', 

18 help='Print available operator mappings.') 

19 

20 common.add_selection_arguments(p) 

21 return p 

22 

23 

24def call(parser, args): 

25 squirrel = common.squirrel_from_selection_arguments(args) 

26 

27 def scodes(codes): 

28 css = list(zip(*(c.split(separator) for c in codes))) 

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

30 return '.'.join( 

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

32 for cs in css) 

33 else: 

34 return ', '.join(c.replace(separator, '.') for c in codes) 

35 

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

37 print('%s <- %s <- %s' % ( 

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