-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_opname.py
executable file
·36 lines (30 loc) · 1.19 KB
/
format_opname.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python2
import sys
import re
import logging
import argparse
def format_op(op):
"format operator from ruby format to david format"
try:
base, rep, p1,c1,o1, p2,c2,o2 = re.match('@oplist.push\("(.*)"\)', op).group(1).split()
except ValueError:
return
iso, n1, n2 = base.split("_")
p1 = "".join(p1.replace("[P=(", "").replace(")", "").split(","))
p2 = "".join(p2.replace("[P=(", "").replace(")", "").split(","))
o1=o1.strip(']\"').replace("_","")
o2=o2.strip(']\"').replace("_","")
rep=rep.replace("_","")
print "{}{}-{}p{}{}{}-{}p{}{}{}".format(iso, rep, n1, p1, o1, c1, n2, p2, o2, c2)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="translate ruby format to colin format")
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
parser.add_argument('strings', metavar='s', type=str, nargs='+',
help='expected level to determine opname from')
args = parser.parse_args()
if args.strings == ["-"]:
args.strings = []
for line in sys.stdin:
args.strings.append( line.strip())
for op in args.strings:
format_op(op)