1 | #!/usr/bin/env python
|
---|
2 | #
|
---|
3 | # This is absolute crap; we really need to parse the impls and process them
|
---|
4 | #
|
---|
5 | import user
|
---|
6 |
|
---|
7 | import os
|
---|
8 | import sys
|
---|
9 | import re
|
---|
10 | import cPickle
|
---|
11 | import project
|
---|
12 | import RDict
|
---|
13 | import commands
|
---|
14 |
|
---|
15 |
|
---|
16 | def getSplicersDir(splicedimpls,dir,names):
|
---|
17 | reg = re.compile('splicer.begin\(([A-Za-z0-9._]*)\)')
|
---|
18 |
|
---|
19 | if 'SCCS' in names: del names[names.index('SCCS')]
|
---|
20 | if 'BitKeeper' in names: del names[names.index('BitKeeper')]
|
---|
21 | if 'docs' in names: del names[names.index('docs')]
|
---|
22 | for f in names:
|
---|
23 | ext = os.path.splitext(f)[1]
|
---|
24 | if not ext in splicedimpls: continue
|
---|
25 | if f == '__init__.py': continue
|
---|
26 | if not os.path.isfile(os.path.join(dir,f)): continue
|
---|
27 | fd = open(os.path.join(dir,f),'r')
|
---|
28 | line = fd.readline()
|
---|
29 | while line:
|
---|
30 | if not line.find('splicer.begin') == -1:
|
---|
31 | fl = reg.search(line)
|
---|
32 | name = fl.group(1)
|
---|
33 |
|
---|
34 | line = fd.readline()
|
---|
35 | body = ''
|
---|
36 | while line.find('splicer.end') == -1:
|
---|
37 | body = body + line
|
---|
38 | line = fd.readline()
|
---|
39 | splicedimpls[ext][name] = body
|
---|
40 |
|
---|
41 | line = fd.readline()
|
---|
42 | fd.close()
|
---|
43 |
|
---|
44 | def getSplicers(directories):
|
---|
45 | splicedimpls = {'.c' : {}, '.h' : {}, '.cc' : {}, '.hh' : {}, '.py' : {}, '.m' : {}}
|
---|
46 |
|
---|
47 | if not directories: directories = [os.getcwd()]
|
---|
48 | for directory in directories:
|
---|
49 | os.path.walk(directory,getSplicersDir,splicedimpls)
|
---|
50 |
|
---|
51 | f = open('splicerblocks', 'w')
|
---|
52 | cPickle.dump(splicedimpls,f)
|
---|
53 | f.close()
|
---|
54 |
|
---|
55 | if __name__ == '__main__':
|
---|
56 | if len(sys.argv) > 2: sys.exit('Usage: getsplicers.py <directory>')
|
---|
57 | getSplicers(sys.argv[1:-1])
|
---|
58 |
|
---|