-
Notifications
You must be signed in to change notification settings - Fork 0
/
codeConverter.py
59 lines (46 loc) · 1.53 KB
/
codeConverter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python
import os
import sys
CODE_PATH = '/build/trees/vdnet/main/automation/'
class codeConverter(object):
def __init__(self):
self.anchorInfo = dict()
def anchorBuilder(self, codepath, anchorinfo = {}):
self.codePath = codepath
for key in anchorinfo.keys():
newkey = key.replace('::','/')
newkey = newkey + '.pm'
newkey = os.path.join(CODE_PATH,newkey)
self.anchorInfo[newkey] = anchorinfo[key]
def getAnchorInfo(self):
return self.anchorInfo
def convertCode(self):
for key in self.anchorInfo.keys():
print "code path: " + key
if os.path.exists(key):
if os.path.isfile(key):
self.readAndMark(key,self.anchorInfo[key])
else:
print '%s is not exist'%key
def readAndMark(self,codepath,linenums):
self.pos = 1
parts = codepath.split('/')
parts = parts[-1].split('.')
outpath = os.path.join('.',parts[0]+'.html')
# outpath = os.path.join('.','1.html')
#print 'outpath' + outpath
out = open(outpath,'wt')
out.write('<html>')
out.write('<body>')
#print "linenums"
#print linenums.count('1')
for eachline in open(codepath, 'r'):
if linenums.count(str(self.pos)) > 0:
#out.write('<div id="%s" style="display:none;">here</div>\n' % self.pos)
out.write('<div id="%s"></div>\n' % self.pos)
eachline = '<fond>%d %s</fond><br/>' % (self.pos,eachline)
out.write(eachline)
self.pos = self.pos + 1
out.write('</body>')
out.write('</html>')
out.close()