rna refactor...
[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], 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 = mod_from_dict.pop(key)
31                 except:
32                         # print("not found", key)
33                         val = val_orig
34
35                 rna_api_new.append(val)
36         
37         def write_work_file(file_path, rna_api):
38                 rna_api = list(rna_api)
39                 rna_api.sort(key=work_line_id)
40                 file_out = open(file_path, "w")
41                 file_out.write("rna_api = [\n")
42                 for line in rna_api:
43                         file_out.write("    %s,\n" % (repr(line)))
44                 file_out.write("]\n")
45                 file_out.close()
46
47         file_path = sys.argv[-2][:-3] + "_merged.py"
48         write_work_file(file_path, rna_api_new)
49         
50         if mod_from_dict:
51                 file_path = sys.argv[-2][:-3] + "_lost.py"
52                 write_work_file(file_path, list(mod_from_dict.values()))
53                 print("Warning '%s' contains lost %d items from module %s.py" % (file_path, len(mod_from_dict), mod_from.__name__))
54
55 if __name__ == "__main__":
56         main()