~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python3
 
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()