-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmfn.py
66 lines (47 loc) · 1.44 KB
/
mfn.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#/usr/bin/python
import re
import os
import sys
RE_TYPE_NAME = re.compile(r'([\s]*k[A-Za-z0-9]+),.*')
CPP_TEMPLATE = (
"""std::string type_names[] = {{
{}
}};
"""
)
def main(*argv):
"""Parse the MFn header file to generate an array of MFn::Type names."""
cmd, devkit_path = (argv or [None, None])
mfn_inl_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'src', 'MFn.Types.inl')
if cmd == 'parse':
_parse(mfn_inl_path, devkit_path)
elif cmd == 'clear':
_clear(mfn_inl_path)
return 0
def _clear(mfn_inl_path):
print('Clearing MFn.Types.inl...')
with open(mfn_inl_path, 'w') as fp:
fp.write('// Auto-generated by /Scripts/mfn.py at build time\n')
def _parse(mfn_inl_path, devkit_path):
print('Parsing MFn.h to MFn.Types.inl...')
mfn_header = os.path.join(devkit_path, 'include', 'maya', 'MFn.h')
with open(mfn_header, 'r') as fp:
lines = fp.readlines()
type_name_list = [
'kInvalid'
]
for line in lines:
match = RE_TYPE_NAME.match(line)
if not match:
continue
type_name = match.groups(0)[0].strip()
type_name_list.append(type_name)
cpp_file = CPP_TEMPLATE.format(
',\n\t'.join(
['"{}"'.format(each) for each in type_name_list]
)
)
with open(mfn_inl_path, 'w') as fp:
fp.write(cpp_file)
if __name__ == '__main__':
main(*sys.argv[1:])