diff options
Diffstat (limited to 'source/blender/makesrna/rna_cleanup/rna_cleaner.py')
-rwxr-xr-x | source/blender/makesrna/rna_cleanup/rna_cleaner.py | 91 |
1 files changed, 61 insertions, 30 deletions
diff --git a/source/blender/makesrna/rna_cleanup/rna_cleaner.py b/source/blender/makesrna/rna_cleanup/rna_cleaner.py index f39ee586237..ae17ade36d7 100755 --- a/source/blender/makesrna/rna_cleanup/rna_cleaner.py +++ b/source/blender/makesrna/rna_cleanup/rna_cleaner.py @@ -6,6 +6,9 @@ This script is used to help cleaning RNA api. Typical line in the input file (elements in [] are optional). [comment *] ToolSettings.snap_align_rotation -> use_snap_align_rotation: boolean [Align rotation with the snapping target] + +Geterate output format from blender run this: + ./blender.bin --background --python ./release/scripts/modules/rna_info.py 2> source/blender/makesrna/rna_cleanup/out.txt """ @@ -73,18 +76,21 @@ def check_commandline(): return (inputfile, sort_priority) -def check_prefix(prop): +def check_prefix(prop, btype): # reminder: props=[comment, changed, bclass, bfrom, bto, kwcheck, btype, description] - if '_' in prop: - prefix = prop.split('_')[0] - if prefix not in kw_prefixes: - return 'BAD-PREFIX: ' + prefix + if btype == "boolean": + if '_' in prop: + prefix = prop.split('_')[0] + if prefix not in kw_prefixes: + return 'BAD-PREFIX: ' + prefix + else: + return prefix + '_' + elif prop in kw: + return 'SPECIAL-KEYWORD: ' + prop else: - return prefix + '_' - elif prop in kw: - return 'SPECIAL-KEYWORD: ' + prop + return 'BAD-KEYWORD: ' + prop else: - return 'BAD-KEYWORD: ' + prop + return "" def check_if_changed(a,b): @@ -103,14 +109,25 @@ def get_props_from_txt(input_filename): props_list=[] props_length_max=[0,0,0,0,0,0,0,0] - for line in file_lines: + + done_text = "+" + done = 0 + tot = 0 + + for iii, line in enumerate(file_lines): # debug #print(line) - + line_strip = line.strip() # empty line or comment - if not line.strip() or line.startswith('#'): + if not line_strip: continue + + if line_strip == "EOF": + break + + if line.startswith("#"): + line = line[1:] # class [bclass, tail] = [x.strip() for x in line.split('.', 1)] @@ -135,22 +152,28 @@ def get_props_from_txt(input_filename): # type, description try: [btype, description] = tail.split(None, 1) - if '"' in description: - description.replace('"', "'") + # make life easy and strip quotes + description = description.replace("'", "").replace('"', "").replace("\\", "").strip() except ValueError: [btype, description] = [tail,'NO DESCRIPTION'] # keyword-check - kwcheck = check_prefix(bto) + kwcheck = check_prefix(bto, btype) # changed changed = check_if_changed(bfrom, bto) # lists formatting - props=[comment, changed, bclass, bfrom, bto, kwcheck, btype, repr(description)] + props=[comment, changed, bclass, bfrom, bto, kwcheck, btype, description] props_list.append(props) props_length_max=list(map(max,zip(props_length_max,list(map(len,props))))) + if done_text in comment: + done += 1 + tot += 1 + + print("Total done %.2f" % (done / tot * 100.0) ) + return (props_list,props_length_max) @@ -165,9 +188,10 @@ def get_props_from_py(input_filename): props_length_max = [0 for i in rna_api[0]] # this way if the vector will take more elements we are safe for index,props in enumerate(rna_api): comment, changed, bclass, bfrom, bto, kwcheck, btype, description = props - kwcheck = check_prefix(bto) # keyword-check + kwcheck = check_prefix(bto, btype) # keyword-check changed = check_if_changed(bfrom, bto) # changed? description = repr(description) + description = description.replace("'", "").replace('"', "").replace("\\", "").strip() rna_api[index] = [comment, changed, bclass, bfrom, bto, kwcheck, btype, description] props_length = list(map(len,props)) # lengths props_length_max = list(map(max,zip(props_length_max,props_length))) # max lengths @@ -189,11 +213,14 @@ def sort(props_list, sort_priority): """ # order based on the i-th element in lists - i = sort_choices.index(sort_priority) - if i == 0: - props_list = sorted(props_list, key=lambda p: p[i], reverse=True) + if sort_priority == "class.to": + props_list = sorted(props_list, key=lambda p: (p[2], p[4])) else: - props_list = sorted(props_list, key=lambda p: p[i]) + i = sort_choices.index(sort_priority) + if i == 0: + props_list = sorted(props_list, key=lambda p: p[i], reverse=True) + else: + props_list = sorted(props_list, key=lambda p: p[i]) print ('\nSorted by %s.' % font_bold(sort_priority)) return props_list @@ -233,16 +260,21 @@ def write_files(basename, props_list, props_length_max): props_list = [['NOTE', 'CHANGED', 'CLASS', 'FROM', 'TO', 'KEYWORD-CHECK', 'TYPE', 'DESCRIPTION']] + props_list for props in props_list: #txt + + # quick way we can tell if it changed + if props[3] == props[4]: txt += "#" + else: txt += " " + if props[0] != '': txt += '%s * ' % props[0] # comment - txt += '%s.%s -> %s: %s %s\n' % tuple(props[2:5] + props[6:]) # skipping keyword-check + txt += '%s.%s -> %s: %s "%s"\n' % tuple(props[2:5] + props[6:]) # skipping keyword-check # rna_api if props[0] == 'NOTE': indent = '# ' else: indent = ' ' - rna += indent + '("%s", "%s", "%s", "%s", %s),\n' % tuple(props[2:5] + props[6:]) # description is alredy string formatted + rna += indent + '("%s", "%s", "%s", "%s", "%s"),\n' % tuple(props[2:5] + props[6:]) # description is already string formatted # py blanks = [' '* (x[0]-x[1]) for x in zip(props_length_max,list(map(len,props)))] props = [('"%s"%s' if props[-1] != x[0] else "%s%s") % (x[0],x[1]) for x in zip(props,blanks)] - py += indent + '(%s, %s, %s, %s, %s, %s, %s, %s),\n' % tuple(props) + py += indent + '(%s, %s, %s, %s, %s, %s, %s, "%s"),\n' % tuple(props) f_txt.write(txt) f_py.write("rna_api = [\n%s]\n" % py) @@ -266,12 +298,11 @@ def main(): global sort_choices, default_sort_choice global kw_prefixes, kw - sort_choices = ['note','changed','class','from','to','kw'] - default_sort_choice = sort_choices[0] - #kw_prefixes = ['invert','is','lock','show','show_only','use','use_only'] - #kw = ['hide','select','layer','state'] - kw_prefixes = ['has','invert','is','lock','layers','show','show_only','states','use','use_only'] - kw = ['layers','states','value'] + sort_choices = ['note','changed','class','from','to','kw', 'class.to'] + default_sort_choice = sort_choices[-1] + kw_prefixes = [ 'active','apply','bl','exclude','has','invert','is','lock', \ + 'pressed','show','show_only','use','use_only','layers','states', 'select'] + kw = ['active','hide','invert','select','layers','mute','states','use','lock'] input_filename, sort_priority = check_commandline() props_list,props_length_max = get_props(input_filename) |