- rna_info.py now outputs array length with types eg. float[16].
[blender-staging.git] / source / blender / makesrna / rna_cleanup / rna_cleaner_merge.py
1 #! /usr/bin/env python3.1
2
3 import sys
4
5 '''
6 Example usage:
7  python3 rna_cleaner_merge.py out_work.py rna_booleans_work.py
8 '''
9 def main():
10         
11         def work_line_id(line):
12                 return line[2].split("|")[-1], line[3] # class/from
13         
14         
15         if not (sys.argv[-1].endswith(".py") and sys.argv[-2].endswith(".py")):
16                 print("Only accepts 2 py files as arguments.")
17         
18         sys.path.insert(0, ".")
19
20         mod_from = __import__(sys.argv[-1][:-3])
21         mod_to = __import__(sys.argv[-2][:-3])
22         
23         mod_to_dict = dict([(work_line_id(line), line) for line in mod_to.rna_api])
24         mod_from_dict = dict([(work_line_id(line), line) for line in mod_from.rna_api])
25         
26         rna_api_new = []
27         
28         for key, val_orig in mod_to_dict.items():
29                 try:
30                         val_new = mod_from_dict.pop(key)
31                 except:
32                         # print("not found", key)
33                         val_new = val_orig
34                         
35                 # always take the class from the base
36                 val = list(val_orig)
37                 val[0] = val_new[0] # comment
38                 val[4] = val_new[4] # -> to
39                 val = tuple(val)
40                 rna_api_new.append(val)
41         
42         def write_work_file(file_path, rna_api):
43                 rna_api = list(rna_api)
44                 rna_api.sort(key=work_line_id)
45                 file_out = open(file_path, "w")
46                 file_out.write("rna_api = [\n")
47                 for line in rna_api:
48                         file_out.write("    %s,\n" % (repr(line)))
49                 file_out.write("]\n")
50                 file_out.close()
51
52         file_path = sys.argv[-2][:-3] + "_merged.py"
53         write_work_file(file_path, rna_api_new)
54         
55         if mod_from_dict:
56                 file_path = sys.argv[-2][:-3] + "_lost.py"
57                 write_work_file(file_path, list(mod_from_dict.values()))
58                 print("Warning '%s' contains lost %d items from module %s.py" % (file_path, len(mod_from_dict), mod_from.__name__))
59
60 if __name__ == "__main__":
61         main()