~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/makesrna/rna_cleanup/rna_cleaner.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.1
 
1
#! /usr/bin/env python3
2
2
 
3
3
"""
4
4
This script is used to help cleaning RNA api.
6
6
Typical line in the input file (elements in [] are optional).
7
7
 
8
8
[comment *] ToolSettings.snap_align_rotation -> use_snap_align_rotation:    boolean    [Align rotation with the snapping target]
 
9
 
 
10
Geterate output format from blender run this:
 
11
 ./blender.bin --background -noaudio --python ./release/scripts/modules/rna_info.py 2> source/blender/makesrna/rna_cleanup/out.txt
9
12
"""
10
13
 
11
14
 
73
76
    return (inputfile, sort_priority)
74
77
 
75
78
 
76
 
def check_prefix(prop):
 
79
def check_prefix(prop, btype):
77
80
    # reminder: props=[comment, changed, bclass, bfrom, bto, kwcheck, btype, description]
78
 
    if '_' in prop:
79
 
        prefix = prop.split('_')[0]
80
 
        if prefix not in kw_prefixes:
81
 
            return 'BAD-PREFIX: ' + prefix
 
81
    if btype == "boolean":
 
82
        if '_' in prop:
 
83
            prefix = prop.split('_')[0]
 
84
            if prefix not in kw_prefixes:
 
85
                return 'BAD-PREFIX: ' + prefix
 
86
            else:
 
87
                return prefix + '_'
 
88
        elif prop in kw:
 
89
            return 'SPECIAL-KEYWORD: ' + prop
82
90
        else:
83
 
            return prefix + '_'
84
 
    elif prop in kw:
85
 
        return 'SPECIAL-KEYWORD: ' + prop
 
91
            return 'BAD-KEYWORD: ' + prop
86
92
    else:
87
 
        return 'BAD-KEYWORD: ' + prop
 
93
        return ""
88
94
 
89
95
 
90
96
def check_if_changed(a,b):
103
109
 
104
110
    props_list=[]
105
111
    props_length_max=[0,0,0,0,0,0,0,0]
106
 
    for line in file_lines:
 
112
    
 
113
    done_text = "+"
 
114
    done = 0
 
115
    tot = 0
 
116
    
 
117
    for iii, line in enumerate(file_lines):
107
118
        
108
119
        # debug
109
120
        #print(line)
110
 
        
 
121
        line_strip = line.strip()
111
122
        # empty line or comment
112
 
        if not line.strip() or line.startswith('#'):
 
123
        if not line_strip:
113
124
            continue
 
125
            
 
126
        if line_strip == "EOF":
 
127
            break
 
128
        
 
129
        if line.startswith("#"):
 
130
            line = line[1:]
114
131
 
115
132
        # class
116
133
        [bclass, tail] = [x.strip() for x in line.split('.', 1)]
135
152
        # type, description
136
153
        try:
137
154
            [btype, description] = tail.split(None, 1)
138
 
            if '"' in description:
139
 
                description.replace('"', "'")
 
155
            # make life easy and strip quotes
 
156
            description = description.replace("'", "").replace('"', "").replace("\\", "").strip()
140
157
        except ValueError:
141
158
            [btype, description] = [tail,'NO DESCRIPTION']
142
159
 
143
160
        # keyword-check
144
 
        kwcheck = check_prefix(bto)
 
161
        kwcheck = check_prefix(bto, btype)
145
162
 
146
163
        # changed
147
164
        changed = check_if_changed(bfrom, bto)
148
165
        
149
166
        # lists formatting
150
 
        props=[comment, changed, bclass, bfrom, bto, kwcheck, btype, repr(description)]
 
167
        props=[comment, changed, bclass, bfrom, bto, kwcheck, btype, description]
151
168
        props_list.append(props)
152
169
        props_length_max=list(map(max,zip(props_length_max,list(map(len,props)))))
153
170
        
 
171
        if done_text in comment:
 
172
            done += 1
 
173
        tot += 1
 
174
    
 
175
    print("Total done %.2f" % (done / tot * 100.0) )
 
176
    
154
177
    return (props_list,props_length_max)
155
178
 
156
179
 
165
188
    props_length_max = [0 for i in rna_api[0]] # this way if the vector will take more elements we are safe
166
189
    for index,props in enumerate(rna_api):
167
190
        comment, changed, bclass, bfrom, bto, kwcheck, btype, description = props
168
 
        kwcheck = check_prefix(bto)   # keyword-check
 
191
        kwcheck = check_prefix(bto, btype)   # keyword-check
169
192
        changed = check_if_changed(bfrom, bto)  # changed?
170
193
        description = repr(description)
 
194
        description = description.replace("'", "").replace('"', "").replace("\\", "").strip()
171
195
        rna_api[index] = [comment, changed, bclass, bfrom, bto, kwcheck, btype, description]
172
196
        props_length = list(map(len,props)) # lengths
173
197
        props_length_max = list(map(max,zip(props_length_max,props_length)))    # max lengths
189
213
    """
190
214
 
191
215
    # order based on the i-th element in lists
192
 
    i = sort_choices.index(sort_priority)
193
 
    if i == 0:
194
 
        props_list = sorted(props_list, key=lambda p: p[i], reverse=True)
 
216
    if sort_priority == "class.to":
 
217
        props_list = sorted(props_list, key=lambda p: (p[2], p[4]))
195
218
    else:
196
 
        props_list = sorted(props_list, key=lambda p: p[i])
 
219
        i = sort_choices.index(sort_priority)
 
220
        if i == 0:
 
221
            props_list = sorted(props_list, key=lambda p: p[i], reverse=True)
 
222
        else:
 
223
            props_list = sorted(props_list, key=lambda p: p[i])
197
224
        
198
225
    print ('\nSorted by %s.' % font_bold(sort_priority))
199
226
    return props_list
233
260
    props_list = [['NOTE', 'CHANGED', 'CLASS', 'FROM', 'TO', 'KEYWORD-CHECK', 'TYPE', 'DESCRIPTION']] + props_list
234
261
    for props in props_list:
235
262
        #txt
 
263
        
 
264
        # quick way we can tell if it changed
 
265
        if props[3] == props[4]: txt += "#"
 
266
        else: txt += " "
 
267
    
236
268
        if props[0] != '': txt +=  '%s * ' % props[0]   # comment
237
 
        txt +=  '%s.%s -> %s:   %s  %s\n' % tuple(props[2:5] + props[6:])   # skipping keyword-check
 
269
        txt +=  '%s.%s -> %s:   %s  "%s"\n' % tuple(props[2:5] + props[6:])   # skipping keyword-check
238
270
        # rna_api
239
271
        if props[0] == 'NOTE': indent = '#   '
240
272
        else: indent = '    '
241
 
        rna += indent + '("%s", "%s", "%s", "%s", %s),\n' % tuple(props[2:5] + props[6:]) # description is already string formatted
 
273
        rna += indent + '("%s", "%s", "%s", "%s", "%s"),\n' % tuple(props[2:5] + props[6:]) # description is already string formatted
242
274
        # py
243
275
        blanks = [' '* (x[0]-x[1]) for x in zip(props_length_max,list(map(len,props)))]
244
276
        props = [('"%s"%s' if props[-1] != x[0] else "%s%s") % (x[0],x[1]) for x in zip(props,blanks)]
245
 
        py += indent + '(%s, %s, %s, %s, %s, %s, %s, %s),\n' % tuple(props)
 
277
        py += indent + '(%s, %s, %s, %s, %s, %s, %s, "%s"),\n' % tuple(props)
246
278
 
247
279
    f_txt.write(txt)
248
280
    f_py.write("rna_api = [\n%s]\n" % py)
266
298
    global sort_choices, default_sort_choice
267
299
    global kw_prefixes, kw
268
300
 
269
 
    sort_choices = ['note','changed','class','from','to','kw']
270
 
    default_sort_choice = sort_choices[0]
 
301
    sort_choices = ['note','changed','class','from','to','kw', 'class.to']
 
302
    default_sort_choice = sort_choices[-1]
271
303
    kw_prefixes = [ 'active','apply','bl','exclude','has','invert','is','lock', \
272
 
                    'pressed','show','show_only','use','use_only','layers','states']
 
304
                    'pressed','show','show_only','use','use_only','layers','states', 'select']
273
305
    kw = ['active','hide','invert','select','layers','mute','states','use','lock']
274
306
 
275
307
    input_filename, sort_priority = check_commandline()