diff options
Diffstat (limited to 'source/blender/makesrna/rna_cleanup')
-rwxr-xr-x | source/blender/makesrna/rna_cleanup/rna_cleaner.py | 34 | ||||
-rwxr-xr-x | source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py | 20 |
2 files changed, 27 insertions, 27 deletions
diff --git a/source/blender/makesrna/rna_cleanup/rna_cleaner.py b/source/blender/makesrna/rna_cleanup/rna_cleaner.py index 8b4b10c490e..0b80a711c3b 100755 --- a/source/blender/makesrna/rna_cleanup/rna_cleaner.py +++ b/source/blender/makesrna/rna_cleanup/rna_cleaner.py @@ -19,7 +19,7 @@ def font_bold(mystring): font_bold = "\033[1m" font_reset = "\033[0;0m" return font_bold + mystring + font_reset - + def usage(): """ @@ -102,30 +102,30 @@ def get_props_from_txt(input_filename): """ If the file is *.txt, the script assumes it is formatted as outlined in this script docstring """ - + file=open(input_filename,'r') file_lines=file.readlines() file.close() props_list=[] props_length_max=[0,0,0,0,0,0,0,0] - + 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: continue - + if line_strip == "EOF": break - + if line.startswith("#"): line = line[1:] @@ -162,18 +162,18 @@ def get_props_from_txt(input_filename): # changed changed = check_if_changed(bfrom, bto) - + # lists formatting 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) @@ -181,7 +181,7 @@ def get_props_from_py(input_filename): """ If the file is *.py, the script assumes it contains a python list (as "rna_api=[...]") This means that this script executes the text in the py file with an exec(text). - """ + """ # adds the list "rna_api" to this function's scope rna_api = __import__(input_filename[:-3]).rna_api @@ -205,7 +205,7 @@ def get_props(input_filename): props_list,props_length_max = get_props_from_py(input_filename) return (props_list,props_length_max) - + def sort(props_list, sort_priority): """ reminder @@ -221,7 +221,7 @@ def sort(props_list, sort_priority): 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 @@ -260,11 +260,11 @@ 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 # rna_api @@ -279,7 +279,7 @@ def write_files(basename, props_list, props_length_max): f_txt.write(txt) f_py.write("rna_api = [\n%s]\n" % py) f_rna.write("rna_api = [\n%s]\n" % rna) - + # write useful py script, wont hurt f_py.write("\n'''\n") f_py.write("for p_note, p_changed, p_class, p_from, p_to, p_check, p_type, p_desc in rna_api:\n") diff --git a/source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py b/source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py index 17ea5f9b0bd..a5d5cebcbb7 100755 --- a/source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py +++ b/source/blender/makesrna/rna_cleanup/rna_cleaner_merge.py @@ -7,38 +7,38 @@ Example usage: python3 rna_cleaner_merge.py out_work.py rna_booleans_work.py ''' def main(): - + def work_line_id(line): return line[2].split("|")[-1], line[3] # class/from - - + + if not (sys.argv[-1].endswith(".py") and sys.argv[-2].endswith(".py")): print("Only accepts 2 py files as arguments.") - + sys.path.insert(0, ".") mod_from = __import__(sys.argv[-1][:-3]) mod_to = __import__(sys.argv[-2][:-3]) - + mod_to_dict = dict([(work_line_id(line), line) for line in mod_to.rna_api]) mod_from_dict = dict([(work_line_id(line), line) for line in mod_from.rna_api]) - + rna_api_new = [] - + for key, val_orig in mod_to_dict.items(): try: val_new = mod_from_dict.pop(key) except: # print("not found", key) val_new = val_orig - + # always take the class from the base val = list(val_orig) val[0] = val_new[0] # comment val[4] = val_new[4] # -> to val = tuple(val) rna_api_new.append(val) - + def write_work_file(file_path, rna_api): rna_api = list(rna_api) rna_api.sort(key=work_line_id) @@ -51,7 +51,7 @@ def main(): file_path = sys.argv[-2][:-3] + "_merged.py" write_work_file(file_path, rna_api_new) - + if mod_from_dict: file_path = sys.argv[-2][:-3] + "_lost.py" write_work_file(file_path, list(mod_from_dict.values())) |