# paths = ['/b/release/ui', '/b/release/io'] paths = ['/b/release', '/b/source/blender/makesrna/intern']
#paths = ['/root/blender-svn/blender/'] tmp = '/tmp/batch_edit.tmp'
import sys, os
def convertSpace2Tabs(lines): for i, l in enumerate(lines): l_strip = l.lstrip() if l_strip: diff = len(l)-len(l_strip) if diff: white = l[:diff] white = white.replace('\t', ' ') white = white.replace(' ', '\t') white = white.replace(' ', '') ''' print "---" print l print white+l[diff:] print ">>>" ''' lines[i] = white+l[diff:]
def convertTabs2Spaces(lines): for i, l in enumerate(lines): l = lines[i] = lines[i].rstrip() + '\n' l_strip = l.lstrip() if l_strip: diff = len(l)-len(l_strip) if diff: white = l[:diff] white = white.replace('\t', ' ') lines[i] = white+l[diff:]
def Fix_b25_enums(lines): for i, l in enumerate(lines): replacements = [] if '"' in l: l_split = l.split('"') if l_split: for j, w in enumerate(l_split): if ' ' not in w and \ '.' not in w and \ ',' not in w and \ '(' not in w and \ ')' not in w and \ '[' not in w and \ ']' not in w and \ '\\' not in w and \ '/' not in w and \ '+' not in w and \ '-' not in w and \ "'" not in w and \ "!" not in w and \ ":" not in w and \ '#' not in w: if w.isupper(): replacements.append(w) replace_ok = False for w in replacements: rep_from = '"'+w+'"' rep_to = "'"+w+"'" # Check this isnt a text arg index = l.find(rep_from) if index != -1: try: arg = l[:index].replace('=', ' ').replace(',', ' ').replace('"', ' ').replace('(', ' ').replace(')', ' ').split()[-1] except: arg = '' if 'text' not in arg: replace_ok= True l = l.replace(rep_from, rep_to) if replace_ok: lines[i] = l def replace_mtx(lines): for i, l in enumerate(lines): l = l.replace('#include "MTC_vectorops.h"', '') l = l.replace('#include "MTC_matrixops.h"', '') l = l.replace('MTC_Mat4Invert(', 'Mat4Invert(') l = l.replace('MTC_Mat3MulVecfl(', 'Mat3MulVecfl(') l = l.replace('MTC_Mat4MulVec4fl(', 'Mat4MulVec4fl(') l = l.replace('MTC_Mat4Ortho(', 'Mat4Ortho(') l = l.replace('MTC_dot3Float(', 'Inpf(') l = l.replace('MTC_Mat4MulVecfl(', 'Mat4MulVecfl(') l = l.replace('MTC_Mat3MulVecd(', 'Mat3MulVecd(') l = l.replace('MTC_Mat4Mul3Vecfl(', 'Mat4Mul3Vecfl(') l = l.replace('MTC_Mat4One(', 'Mat4One(') l = l.replace('MTC_Mat4CpyMat4(', 'Mat4CpyMat4(') l = l.replace('MTC_Mat3CpyMat4(', 'Mat3CpyMat4(') l = l.replace('MTC_Mat4MulMat4(', 'Mat4MulMat4(') l = l.replace('MTC_Mat4SwapMat4(', 'Mat4SwapMat4(') l = l.replace('MTC_cross3Float(', 'Crossf(') l = l.replace('MTC_diff3Float(', 'VecSubf(') l = l.replace('MTC_Mat4MulSerie(', 'Mat4MulSerie(') lines[i] = l
def replace_25_ui(lines): def foo(l, from_, to_): l = l.replace(from_, to_) l = l.replace('"'+from_[:-1]+'"', '"'+to_[:-1]+'"') return l for i, l in enumerate(lines): l = foo(l, 'itemR(', 'prop(') l = foo(l, 'items_enumR(', 'props_enum(') l = foo(l, 'item_menu_enumR(', 'prop_menu_enum(') l = foo(l, 'item_pointerR(', 'prop_pointer(') l = foo(l, 'itemO(', 'operator(') l = foo(l, 'item_enumO(', 'operator_enum(') l = foo(l, 'items_enumO(', 'operator_enums(') l = foo(l, 'item_menu_enumO(', 'operator_menu_enum(') l = foo(l, 'item_booleanO(', 'operator_boolean(') l = foo(l, 'item_intO(', 'operator_int(') l = foo(l, 'item_floatO(', 'operator_float(') l = foo(l, 'item_stringO(', 'operator_string(') l = foo(l, 'itemL(', 'label(') l = foo(l, 'itemM(', 'menu(') l = foo(l, 'itemS(', 'separator(')
lines[i] = l
def replace_7_curve(lines): for i, l in enumerate(lines): ll = l if "->type" in l and "7" in l and '&' in l and ('pNurb' in l or "nu" in l): #l = l.replace('&7', '& 7') #l = l.replace('& 7', '& 7') l = l.replace('if((nu->type & 7)==CU_BEZIER)', 'if(nu->type == CU_BEZIER)') l = l.replace('if((nu1->type & 7)==CU_BEZIER)', 'if(nu1->type == CU_BEZIER)') l = l.replace('if( (nu->type & 7)==CU_BEZIER )', 'if(nu->type == CU_BEZIER)') l = l.replace('if( (nu->type & 7)==CU_BEZIER)', 'if(nu->type == CU_BEZIER)') l = l.replace('((nu->type & 7)==CU_NURBS)', '(nu->type == CU_NURBS)') l = l.replace('((nu->type & 7)!=CU_BEZIER)', '(nu->type != CU_BEZIER)') l = l.replace('((nu->type & 7)==CU_BEZIER)', '(nu->type == CU_BEZIER)') l = l.replace('((nu->type & 7)!=CU_NURBS)', '(nu->type != CU_NURBS)') l = l.replace('((nu1->type & 7)==CU_NURBS)', '(nu1->type == CU_NURBS)') l = l.replace('((nu->type & 7)==CU_POLY)', '(nu->type == CU_POLY)') l = l.replace('( (nu->type & 7)==CU_POLY )', '(nu->type == CU_POLY)') l = l.replace('((nu->type & 7)==1)', '(nu->type == CU_BEZIER)') l = l.replace('switch(nu->type & 7)', 'switch(nu->type)') l = l.replace('(nu->type & 7)==CU_NURBS', 'nu->type == CU_NURBS') l = l.replace('((nu->type & 7) == CU_BEZIER)', '(nu->type == CU_BEZIER)') if l != ll: # print l[:-1] pass else: print l[:-1] pass lines[i] = l static = ''' weightSetData winqreadnodespace wm_search_menu_poll write_voxeldata_header xsortvert_flag zero_lfvector '''.split() def find_funcs(lines, fname, funcs): ignore = ['for', 'if', 'float', 'while'] for i, l in enumerate(lines): if not l.startswith('\t') and not l.startswith(' '): if '(' in l and ')' in l: l_strip = l.strip() if not l_strip.startswith('//'): if not l_strip.startswith('/*'): if not l_strip.startswith('#'): #if l_strip.endswith('{') or (i+1 != len(lines) and '{' in lines[i+1]): if 1: if 'typedef' not in l: if '#define' not in l: if 'enum' not in l: # were looking for non-static funcs if 'static' not in l and "_OT_" not in l: f = l.split('(')[0] if f: f = f.split()[-1] f = f.split('*')[-1] f = f.strip() if f and f not in ignore and len(f) > 3: # print f # funcs[f] = {} if f in static: # MAKE STATIC lines[i] = 'static ' + l
def get_lines(f): file = open(f, 'r') lines = file.readlines() file.close() return lines
def write_lines(f, lines): file = open(f, 'w') file.writelines(lines) file.close()
def do_file_cmake_ws(f): if not f.endswith('.txt'): return lines = get_lines(f) convertSpace2Tabs(lines) write_lines(f, lines)
def do_pep8_ws(f): if not f.endswith('.py'): return lines = get_lines(f) convertTabs2Spaces(lines) write_lines(f, lines) def do_ui_funcs(f): if not f.endswith('.py') and not f.endswith('.c'): return lines = get_lines(f) replace_25_ui(lines) write_lines(f, lines)
def do_file_25_enum(f): if not f.endswith('.py'): return lines = get_lines(f) Fix_b25_enums(lines) write_lines(f, lines) def do_file_MTC_replace(f): if not f.endswith('.c'): return lines = get_lines(f) replace_mtx(lines) write_lines(f, lines)
def do_file_7_curve(f): if not f.endswith('.c'): return lines = get_lines(f) replace_7_curve(lines) write_lines(f, lines)
def do_file_extract_funcs(f): if not f.endswith('.c'): return lines = get_lines(f) find_funcs(lines, f, do_file_extract_funcs.funcs) write_lines(f, lines) do_file_extract_funcs.funcs = {}
files = [] for path in paths: cmd = 'find "' + path + '" -name "*.*" -print | grep -v "\.svn" > ' + tmp os.system( cmd ) print cmd file = open(tmp, 'rU') files.extend([l.strip() for l in file.readlines()]) file.close()
for f in files: # print(f) # do_pep8_ws(f) # <- change for different utility functions. do_ui_funcs(f)
os.system('rm /tmp/batch_edit.tmp')
print "DONE!"
# paths = ['/b/release/ui', '/b/release/io'] paths = ['/b/release', '/b/source/blender/makesrna/intern'] #paths = ['/root/blender-svn/blender/'] tmp = '/tmp/batch_edit.tmp' import sys, os def convertSpace2Tabs(lines): for i, l in enumerate(lines): l_strip = l.lstrip() if l_strip: diff = len(l)-len(l_strip) if diff: white = l[:diff] white = white.replace('\t', ' ') white = white.replace(' ', '\t') white = white.replace(' ', '') ''' print "---" print l print white+l[diff:] print ">>>" ''' lines[i] = white+l[diff:] def convertTabs2Spaces(lines): for i, l in enumerate(lines): l = lines[i] = lines[i].rstrip() + '\n' l_strip = l.lstrip() if l_strip: diff = len(l)-len(l_strip) if diff: white = l[:diff] white = white.replace('\t', ' ') lines[i] = white+l[diff:] def Fix_b25_enums(lines): for i, l in enumerate(lines): replacements = [] if '"' in l: l_split = l.split('"') if l_split: for j, w in enumerate(l_split): if ' ' not in w and \ '.' not in w and \ ',' not in w and \ '(' not in w and \ ')' not in w and \ '[' not in w and \ ']' not in w and \ '\\' not in w and \ '/' not in w and \ '+' not in w and \ '-' not in w and \ "'" not in w and \ "!" not in w and \ ":" not in w and \ '#' not in w: if w.isupper(): replacements.append(w) replace_ok = False for w in replacements: rep_from = '"'+w+'"' rep_to = "'"+w+"'" # Check this isnt a text arg index = l.find(rep_from) if index != -1: try: arg = l[:index].replace('=', ' ').replace(',', ' ').replace('"', ' ').replace('(', ' ').replace(')', ' ').split()[-1] except: arg = '' if 'text' not in arg: replace_ok= True l = l.replace(rep_from, rep_to) if replace_ok: lines[i] = l def replace_mtx(lines): for i, l in enumerate(lines): l = l.replace('#include "MTC_vectorops.h"', '') l = l.replace('#include "MTC_matrixops.h"', '') l = l.replace('MTC_Mat4Invert(', 'Mat4Invert(') l = l.replace('MTC_Mat3MulVecfl(', 'Mat3MulVecfl(') l = l.replace('MTC_Mat4MulVec4fl(', 'Mat4MulVec4fl(') l = l.replace('MTC_Mat4Ortho(', 'Mat4Ortho(') l = l.replace('MTC_dot3Float(', 'Inpf(') l = l.replace('MTC_Mat4MulVecfl(', 'Mat4MulVecfl(') l = l.replace('MTC_Mat3MulVecd(', 'Mat3MulVecd(') l = l.replace('MTC_Mat4Mul3Vecfl(', 'Mat4Mul3Vecfl(') l = l.replace('MTC_Mat4One(', 'Mat4One(') l = l.replace('MTC_Mat4CpyMat4(', 'Mat4CpyMat4(') l = l.replace('MTC_Mat3CpyMat4(', 'Mat3CpyMat4(') l = l.replace('MTC_Mat4MulMat4(', 'Mat4MulMat4(') l = l.replace('MTC_Mat4SwapMat4(', 'Mat4SwapMat4(') l = l.replace('MTC_cross3Float(', 'Crossf(') l = l.replace('MTC_diff3Float(', 'VecSubf(') l = l.replace('MTC_Mat4MulSerie(', 'Mat4MulSerie(') lines[i] = l def replace_25_ui(lines): def foo(l, from_, to_): l = l.replace(from_, to_) l = l.replace('"'+from_[:-1]+'"', '"'+to_[:-1]+'"') return l for i, l in enumerate(lines): l = foo(l, 'itemR(', 'prop(') l = foo(l, 'items_enumR(', 'props_enum(') l = foo(l, 'item_menu_enumR(', 'prop_menu_enum(') l = foo(l, 'item_pointerR(', 'prop_pointer(') l = foo(l, 'itemO(', 'operator(') l = foo(l, 'item_enumO(', 'operator_enum(') l = foo(l, 'items_enumO(', 'operator_enums(') l = foo(l, 'item_menu_enumO(', 'operator_menu_enum(') l = foo(l, 'item_booleanO(', 'operator_boolean(') l = foo(l, 'item_intO(', 'operator_int(') l = foo(l, 'item_floatO(', 'operator_float(') l = foo(l, 'item_stringO(', 'operator_string(') l = foo(l, 'itemL(', 'label(') l = foo(l, 'itemM(', 'menu(') l = foo(l, 'itemS(', 'separator(') lines[i] = l def replace_7_curve(lines): for i, l in enumerate(lines): ll = l if "->type" in l and "7" in l and '&' in l and ('pNurb' in l or "nu" in l): #l = l.replace('&7', '& 7') #l = l.replace('& 7', '& 7') l = l.replace('if((nu->type & 7)==CU_BEZIER)', 'if(nu->type == CU_BEZIER)') l = l.replace('if((nu1->type & 7)==CU_BEZIER)', 'if(nu1->type == CU_BEZIER)') l = l.replace('if( (nu->type & 7)==CU_BEZIER )', 'if(nu->type == CU_BEZIER)') l = l.replace('if( (nu->type & 7)==CU_BEZIER)', 'if(nu->type == CU_BEZIER)') l = l.replace('((nu->type & 7)==CU_NURBS)', '(nu->type == CU_NURBS)') l = l.replace('((nu->type & 7)!=CU_BEZIER)', '(nu->type != CU_BEZIER)') l = l.replace('((nu->type & 7)==CU_BEZIER)', '(nu->type == CU_BEZIER)') l = l.replace('((nu->type & 7)!=CU_NURBS)', '(nu->type != CU_NURBS)') l = l.replace('((nu1->type & 7)==CU_NURBS)', '(nu1->type == CU_NURBS)') l = l.replace('((nu->type & 7)==CU_POLY)', '(nu->type == CU_POLY)') l = l.replace('( (nu->type & 7)==CU_POLY )', '(nu->type == CU_POLY)') l = l.replace('((nu->type & 7)==1)', '(nu->type == CU_BEZIER)') l = l.replace('switch(nu->type & 7)', 'switch(nu->type)') l = l.replace('(nu->type & 7)==CU_NURBS', 'nu->type == CU_NURBS') l = l.replace('((nu->type & 7) == CU_BEZIER)', '(nu->type == CU_BEZIER)') if l != ll: # print l[:-1] pass else: print l[:-1] pass lines[i] = l static = ''' weightSetData winqreadnodespace wm_search_menu_poll write_voxeldata_header xsortvert_flag zero_lfvector '''.split() def find_funcs(lines, fname, funcs): ignore = ['for', 'if', 'float', 'while'] for i, l in enumerate(lines): if not l.startswith('\t') and not l.startswith(' '): if '(' in l and ')' in l: l_strip = l.strip() if not l_strip.startswith('//'): if not l_strip.startswith('/*'): if not l_strip.startswith('#'): #if l_strip.endswith('{') or (i+1 != len(lines) and '{' in lines[i+1]): if 1: if 'typedef' not in l: if '#define' not in l: if 'enum' not in l: # were looking for non-static funcs if 'static' not in l and "_OT_" not in l: f = l.split('(')[0] if f: f = f.split()[-1] f = f.split('*')[-1] f = f.strip() if f and f not in ignore and len(f) > 3: # print f # funcs[f] = {} if f in static: # MAKE STATIC lines[i] = 'static ' + l def get_lines(f): file = open(f, 'r') lines = file.readlines() file.close() return lines def write_lines(f, lines): file = open(f, 'w') file.writelines(lines) file.close() def do_file_cmake_ws(f): if not f.endswith('.txt'): return lines = get_lines(f) convertSpace2Tabs(lines) write_lines(f, lines) def do_pep8_ws(f): if not f.endswith('.py'): return lines = get_lines(f) convertTabs2Spaces(lines) write_lines(f, lines) def do_ui_funcs(f): if not f.endswith('.py') and not f.endswith('.c'): return lines = get_lines(f) replace_25_ui(lines) write_lines(f, lines) def do_file_25_enum(f): if not f.endswith('.py'): return lines = get_lines(f) Fix_b25_enums(lines) write_lines(f, lines) def do_file_MTC_replace(f): if not f.endswith('.c'): return lines = get_lines(f) replace_mtx(lines) write_lines(f, lines) def do_file_7_curve(f): if not f.endswith('.c'): return lines = get_lines(f) replace_7_curve(lines) write_lines(f, lines) def do_file_extract_funcs(f): if not f.endswith('.c'): return lines = get_lines(f) find_funcs(lines, f, do_file_extract_funcs.funcs) write_lines(f, lines) do_file_extract_funcs.funcs = {} files = [] for path in paths: cmd = 'find "' + path + '" -name "*.*" -print | grep -v "\.svn" > ' + tmp os.system( cmd ) print cmd file = open(tmp, 'rU') files.extend([l.strip() for l in file.readlines()]) file.close() for f in files: # print(f) # do_pep8_ws(f) # <- change for different utility functions. do_ui_funcs(f) os.system('rm /tmp/batch_edit.tmp') print "DONE!"
|