3
# This is absolute crap; we really need to parse the impls and process them
13
def setSplicersDir(splicedimpls,dir,names):
15
reg = re.compile('splicer.begin\(([A-Za-z0-9._]*)\)')
16
reginclude = re.compile('#include [ ]*"([a-zA-Z_0-9/]*.[h]*)"')
18
if 'SCCS' in names: del names[names.index('SCCS')]
19
if 'BitKeeper' in names: del names[names.index('BitKeeper')]
20
if 'docs' in names: del names[names.index('docs')]
22
ext = os.path.splitext(f)[1]
23
if not ext in splicedimpls: continue
24
if f == '__init__.py': continue
25
if not os.path.isfile(os.path.join(dir,f)): continue
26
fd = open(os.path.join(dir,f),'r')
32
if not line.find('splicer.begin') == -1:
38
while line.find('splicer.end') == -1:
43
# replace body with saved splicer block
44
if name.endswith('._includes') and ext == '.cc':
46
# print 'handling includes for class '+name
49
body = '#include "SIDL.hh"\n'
50
for n in splicedimpls[ext]:
51
if n.startswith(name) and n.endswith('._includes') and n[len1+1:-10].find('.') == -1:
53
body = body + splicedimpls[ext][n]
54
elif name in splicedimpls[ext]:
56
# print 'Replacing -------'+name
58
# print 'with ------------'
59
# print splicedimpls[ext][name]
60
body = splicedimpls[ext][name]
62
# print 'Cannot find splicer block '+name+' '+f+' ext '+ext
65
# convert ASE directory hierarchy of includes
67
for l in body.split('\n'):
68
if reginclude.search(l):
69
fname = reginclude.match(l).group(1)
70
(fn,extmp) = os.path.splitext(fname)
72
if len(fn) > 1 and fn[-1] == fn[-2]:
73
t = '#include "'+string.join(fn[0:-1],'_')+'.hh"'
86
# print 'Replaced blocks in '+os.path.join(dir,f)
87
fd = open(os.path.join(dir,f),'w')
93
def setSplicers(directory):
95
f = open('splicerblocks', 'r')
96
splicedimpls = cPickle.load(f)
99
# change SIDL.Args and SIDL.ProjectState impl names
100
replaces = {'SIDL.Args':'SIDLASE.Args','SIDL.ProjectState':'SIDLASE.ProjectState'}
101
for i in splicedimpls:
102
sillytmp = splicedimpls[i]
105
if not string.find(j,k) == -1:
106
newname = j.replace(k,replaces[k])
107
# print 'Converting '+j+' to '+newname+' ext '+i
108
splicedimpls[i][newname] = splicedimpls[i][j]
109
del splicedimpls[i][j]
112
regset = re.compile('\.set\(([->< a-zA-Z_0-9/.\(\)\[\]&+*]*),([->< a-zA-Z_0-9/.\(\)\[\]&+*]*)\)[ ]*;')
113
regcreate = re.compile('\.create\(([->< a-zA-Z_0-9/.\(\)\[\]&+*]*),([->< a-zA-Z_0-9/.\(\)\[\]&+*]*),([->< a-zA-Z_0-9/.\(\)\[\]&+*]*)\)[ ]*;')
114
replaces = {'SIDL/Args':'SIDLASE/Args', 'SIDL/ProjectState':'SIDLASE/ProjectState',
115
'SIDL::Args':'SIDLASE::Args', 'SIDL::ProjectState':'SIDLASE::ProjectState',
116
'.dim(':'.dimen(', '.destroy(':'.deleteRef(',
117
'.setMessage(':'.setNote(', '.getMessage(':'getNote(',
118
'.isInstanceOf(':'.isType(', ' IDENT':' MPIB::IDENT',
119
' SIMILAR':' MPIB::SIMILAR', ' CONGRUENT':' MPIB::CONGRUENT',
121
for i in splicedimpls:
122
for j in splicedimpls[i]:
123
if regset.search(splicedimpls[i][j]):
124
splicedimpls[i][j] = regset.sub('.set(\\2,\\1);',splicedimpls[i][j])
125
if regcreate.search(splicedimpls[i][j]):
126
splicedimpls[i][j] = regcreate.sub('.createRow(\\1,\\2,\\3);',splicedimpls[i][j])
128
splicedimpls[i][j] = splicedimpls[i][j].replace(k,replaces[k])
130
if not directory: directory = os.getcwd()
131
os.path.walk(directory,setSplicersDir,splicedimpls)
134
if __name__ == '__main__':
135
if len(sys.argv) > 2: sys.exit('Usage: getsplicers.py <directory>')
136
sys.argv.append(None)
137
setSplicers(sys.argv[1])