15 import sys, os, urllib2, copy
16 from BeautifulSoup
import *
18 except ImportError:
import simplejson
as json
33 dataSrc =
'http://cmsdoxy.web.cern.ch/cmsdoxy/cmssw/cmssw.php?ver='
34 githubBase =
'https://github.com/cms-sw/cmssw/tree/{0}/{1}'
43 with open(filesPagePath)
as f: page = f.read()
48 table = page.find(
'table', {
'class' :
'directory'})
51 for row
in table.findAll(
'tr'):
53 id = row[
'id']; cell = row.find(
'td')
54 text = cell.text; url =
'../' + cell.find(
'a')[
'href']
55 currentLevel = id.count(
'_')
57 if currentLevel > level:
60 elif currentLevel == level:
61 path.pop(len(path) - 1)
66 for i
in range(level - currentLevel + 1):
67 path.pop(len(path) - 1)
71 if not 'interface' in path:
continue
73 pathWithoutInterface = copy.copy(path)
74 pathWithoutInterface.remove(
'interface')
77 for i
in pathWithoutInterface:
78 if not node.has_key(i):
85 with open(packagesPagePath)
as f: page = f.read()
87 table = page.find(
'table', {
'class' :
'directory'})
88 for row
in table.findAll(
'tr'):
90 url =
'../' + cell.find(
'a')[
'href']
93 pkg = cell.text.replace(
'Package ',
'').
split(
'/')
94 if not data.has_key(pkg[0]): data[pkg[0]] = {}
95 if len(pkg) == 2: data[pkg[0]][pkg[1]] = url
96 else: data[pkg[0]][pkg[0]] = url
101 with open(classesPagePath)
as f: page = f.read()
103 content = page.find(
'div', {
'class' :
'contents'})
104 for cell
in content.findAll(
'td'):
105 aTag = cell.find(
'a')
106 if not aTag
or not aTag.has_key(
'href'):
continue
107 data[aTag.text] =
'../' + aTag[
'href']
113 header = htmlPage.find(
'div', {
'class' :
'header'})
114 content = htmlPage.find(
'div', {
'class' :
'contents'})
116 for tag
in header.findAll():
118 for tag
in content.findAll():
122 if inp.find_parent(
"script")
is None:
return EntitySubstitution.substitute_html(inp)
131 for scriptTag
in BeautifulSoup(contentTmplOrg).findAll(
'script'):
133 html = html.replace(str(scriptTag),
'<script>%s</script>' % js)
138 rowTmpl =
'<tr id="{0}"><td width="50%">{1}</td><td>{2}</td></tr>'
139 aTmpl =
"""<tr style="padding:0"><td colspan="2" style="padding:0">
140 <div class="accordion" id="{0}">
141 <iframe width="100%" height="250px" frameborder="0"
142 data-src="iframes/{0}.html"> </iframe>
144 domainNames = domains.keys()
146 for domain
in domainNames:
147 persons = domains[domain].
keys()
150 for person
in persons:
151 email = domains[domain][person]
152 cCell = cCell+
'<a href="mailto:{0}">{0}<a/>, '.
format(person,email)
153 cCell = cCell.rstrip(
', ')
154 escapedDomainName = domain.replace(
' ',
'')
155 rows = rows + rowTmpl.format(escapedDomainName, domain, cCell)
156 rows = rows + aTmpl.format(escapedDomainName)
159 contentTmpl.find(
'h2', {
'id' :
'version'}).
append(cmsswVersion)
160 content = htmlPage.find(
'div', {
'class' :
'contents'})
161 content.append(contentTmpl)
164 if type(tree) == dict
and len(tree) == 0:
return BeautifulSoup(
'')
167 names = tree.keys(); names.sort()
170 if type(tree[name]) == dict:
172 title.span.append(name)
173 node.li.append(title)
177 for i
in [
'__git__',
'__packageDoc__']:
178 if not i
in tree[name]:
continue
180 link.a[
'target'] =
'_blank'
181 link.a[
'href'] = tree[name][i]
182 link.a.append(
'[%s]' % i.replace(
'_',
''))
184 title.span.append(link)
185 if len(tree[name]) == 0:
186 title.span[
'class'] =
'emptyFolder'
187 else: node.li.div[
'class'] =
'hitarea expandable-hitarea'
189 elif type(tree[name]) == str
or type(tree[name]) == unicode:
191 link.a[
'target'] =
'_blank'
192 link.a[
'href'] = tree[name]
193 link.a.span.append(name)
202 treeTag = page.find(
'ul', {
'id' :
'browser'})
204 twikiLink = page.find(
'a', {
'id' :
'twiki'})
205 if name
in data[
'TWIKI_PAGES']:
206 twikiLink[
'href'] = data[
'TWIKI_PAGES'][name]
212 if __name__ ==
"__main__":
213 if len(sys.argv) < 4:
214 sys.stderr.write(
"not enough parameter!\n")
215 sys.stderr.write(
"first pram must be full path of index.html page\n")
216 sys.stderr.write(
"second pram must be full path of index template\n")
217 sys.stderr.write(
"third one must be the CMSSW version\n")
220 htmlFullPath = sys.argv[1]
222 with open(
'%s/IndexContentTemplate.html' % sys.argv[2])
as f:
223 contentTmplOrg = f.read()
224 with open(
'%s/TreeViewTemplate.html' % sys.argv[2])
as f:
225 treeViewTmpl = f.read()
227 dataSrc = dataSrc + sys.argv[3]
228 htmlFilePath = os.path.split(htmlFullPath)[0]
229 htmlFileName = os.path.split(htmlFullPath)[1]
230 cmsswVersion = sys.argv[3]
233 with open(htmlFullPath)
as f: htmlPage =
BeautifulSoup(f.read())
236 successFlag =
False; loopLimit = 3
237 while(
not successFlag
and loopLimit > 0):
238 loopLimit = loopLimit - 1
240 print 'reading data from cmsdoxy/CMSSWTagCollector...'
241 data = urllib2.urlopen(dataSrc).
read()
242 data = json.loads(data)
245 print 'I couldn\'t get the data. Trying again...'
249 sys.stderr.write(
"I couldn't get the data from %s\n" % dataSrc)
250 sys.stderr.write(
"I am not able to generate the main page, ")
251 sys.stderr.write(
"I will leave it as it is...\n")
252 sys.stderr.write(
"# PLEASE SEND AN EMAIL TO cmsdoxy[at]cern.ch\n")
255 print 'parsing source file hierarchy...'
258 print 'parsing packages...'
261 print 'parsing classes...'
264 tree = copy.copy(data[
'CMSSW_CATEGORIES'])
265 print "generating tree views..."
268 for l1
in tree[domain]:
269 for l2
in tree[domain][l1]:
271 link = githubBase.format(cmsswVersion,
'%s/%s'%(l1,l2))
272 tree[domain][l1][l2][
'__git__'] = link
274 if packages.has_key(l1)
and packages[l1].has_key(l2):
275 tree[domain][l1][l2][
'__packageDoc__'] = packages[l1][l2]
276 if not l1
in files
or not l2
in files[l1]:
continue
277 for file
in files[l1][l2]:
279 file = file.replace(
'.h',
'')
280 if not file
in tree[domain][l1][l2]:
281 tree[domain][l1][l2] = {}
283 tree[domain][l1][l2][file] = classes[file]
285 tree[domain][l1][l2][file] =
None
291 print "generating mainpage..."
294 with open(
"%s/index.html" % htmlFilePath,
'w')
as f:
297 print 'generating domain pages...'
301 fName = domain.replace(
' ',
'')
302 with open(
'%s/iframes/%s.html' % (htmlFilePath, fName),
'w')
as f: