2
import os,re,sys,os.path
4
if not os.path.exists('SConstruct'): raise 'Must be run from the top-level source directory'
5
oldClass,newClass=sys.argv[1],sys.argv[2]
6
replCnt,moveCnt,moveDirCnt=0,0,0
8
for root, dirs, files in os.walk('.'):
10
if os.path.isdir(root+'/'+name): continue
11
if not name.endswith('pp') and name!='SConscript': continue
12
modified=False; new=[]; fullName=root+'/'+name
13
if fullName.startswith('./lib/') or fullName.startswith('./extra'): continue
14
for l in open(fullName):
15
nl,cnt=re.subn(r'\b'+oldClass+r'\b',newClass,l)
17
new.append(nl); modified=True; replCnt+=1
19
# write back the file if it was modified
21
print 'Updated: ',root+'/'+name
22
f=open(root+'/'+name,'w')
23
for l in new: f.write(l)
25
# try to replace the class within the filename, move using bzr if it has changed
26
newName,cnt=re.subn(r'\b'+oldClass+r'\b',newClass,name)
28
newFullName=root+'/'+newName
29
os.system('bzr mv '+fullName+' '+newFullName)
32
# walk directories and change them with bzr if they match exactly (rarely useful)
33
for root, dirs, files in os.walk('.'):
36
os.system('bzr mv %s/%s %s/%s'%(root,oldClass,root,newClass))
39
print "Replaced %d occurences, moved %d files and %d directories"%(replCnt,moveCnt,moveDirCnt)
40
print "Update python scripts (if wanted) by running: perl -pi -e 's/\\b%s\\b/%s/g' `ls **/*.py **/*.rst |grep -v py/system.py`"%(oldClass,newClass)
41
import time,pwd,socket
42
# update python deprecation records
43
if replCnt+moveCnt+moveDirCnt==0:
44
print "No replaces, not updating py/system.py deprecated names map."
47
for l in open('py/system.py'):
48
if 'END_RENAMED_CLASSES_LIST' in l: new+="\t'%s':'%s', # %s, %s@%s\n"%(oldClass,newClass,time.asctime(),pwd.getpwuid(os.getuid())[0],socket.gethostname())
50
f=open('py/system.py','w')
51
for l in new: f.write(l)