CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Splitter.py
Go to the documentation of this file.
1 from BeautifulSoup import *
2 import sys
3 
4 ## Splitter class is used for splitting class and namespace web pages to reduce access time.
5 class Splitter:
6  # @param path is the reference manual directory path and it is used as destination and source.
7  # @param fileName is output file name. (You should consider the menu.js script (/cmsdoxygen/common/menu.js) while you are naming output file)
8  # @param prefix is used for file naming as prefix.
9  def __init__(self, path, fileName, prefix):
10  self.fileName = fileName
11  self.filePath = path
12  self.prefix = prefix
13 
14  self.backupPrefix= prefix + 'backup_'
15  self.headerStamp = '<div class="header">'
16  self.contentStamp= '<div class="contents">'
17  self.footerStamp = '<hr class="footer"/>'
18  self.namespaceImg= 'ftv2ns.png'
19  self.classImg = 'ftv2cl.png'
20 
21  #Min depth
22  self.minD = 2
23  self.chr = '_'
24  self.List = ()
25 
26  file = open(path + fileName, 'r')
27  self.source = file.read()
28  file.close()
29 
30  self.headerPos = self.source.find(self.headerStamp)
31  self.contentPos = self.source.find(self.contentStamp)
32  self.footerPos = self.source.find(self.footerStamp)
33 
34  self.parsedSource= None
35 
36  def GetHeader(self):
37  return self.source[0:self.headerPos]
38 
39  def GetDivHeader(self):
40  return self.source[self.headerPos:self.contentPos]
41 
42  def GetFooter(self):
43  """This method returns footer of the input page"""
44  return self.source[self.footerPos:len(self.source)]
45 
46  def GetContent(self):
47  """This method returns content of the input page"""
48  return self.source[self.contentPos:self.footerPos]
49 
50  def WritePage(self, fileName, data):
51  f = open(self.filePath + fileName, "w")
52  f.write(data)
53  f.close()
54 
55  def Backup(self):
56  #backup
57  self.WritePage(self.backupPrefix + 'deep_' + self.fileName, self.source)
58 
59  #editted backup
60  edb = self.GetHeader() + self.CreateTab("All") + self.GetDivHeader() + self.GetContent() + self.GetFooter()
61  self.WritePage(self.prefix + '_ALL.html', edb)
62 
63  def __GetName(self, node):
64  if node.a:
65  return node.a.contents[0]
66  elif node.b:
67  return node.b.contents[0]
68  else:
69  return "---------"
70 
71  def __GetInfo(self, node):
72  if node.findAll("td", {"class":"desc"}):
73  return node.findAll("td", {"class":"desc"})[0].text
74  else:
75  return ""
76 
77  def __IsLink(self, node):
78  """This method returns true if it has link."""
79  if(node.a): return True
80  else: return False
81 
82  def __GetLink(self, node):
83  """This method returns node link."""
84  return node.a['href']
85 
86  def __GetDepth(self, node):
87  """This method returns depth of the node. To determine this, '_' character is used."""
88  # <tr id="row_0_" ... It has two '_' character
89  # <tr id="row_0_0_" ... It has three '_' character
90  return node["id"].count(self.chr) - self.minD
91 
92  def CreateTab(self, current):
93  # If source code was not parsed
94  if not self.parsedSource:
95  self.parsedSource = self.GetNsC()
96  header = '<div class="tabs3" align="center">\n<ul class="tablist">\n'
97  if current == "All":
98  all_ = '<li class="current"><a href="%s"><span>All</span></a></li>\n' % (self.prefix + '_ALL.html')
99  else:
100  all_ = '<li><a href="%s"><span>All</span></a></li>\n' % (self.prefix + '_ALL.html')
101  footer = '</ul>\n</div>\n'
102  tab = ''
103 
104  tab = header
105  for i in self.List:
106  if i != current:
107  tab = tab + u'<li><a href="%s"><span>%s</span></a></li>\n' % ("%s%s.html" % (self.prefix, i), i)
108  else:
109  tab = tab + u'<li class="current"><a href="%s"><span>%s</span></a></li>\n' % ("%s%s.html" % (self.prefix, current), i)
110 
111  tab = tab + all_ + footer
112 
113  return tab.encode("ascii")
114 
115  def CreatePage(self, current, itemList):
116  """This method creates web page."""
117  data = ""
118  data = self.GetHeader()
119  data = data + self.CreateTab(current)
120  data = data + self.GetDivHeader()
121  data = data + '<div class="contents"><table width="100%">'
122 
123  for i in itemList:
124  data = data + '<tr><td class="indexkey"><a class="el" href="%s">%s</a></td><td class="indexvalue">%s</td></tr>\n' % i
125 
126  data = data + '</table></div>'
127  data = data + self.GetFooter()
128  return data
129 
130  def CreatePages(self):
131  self.Backup()
132  self.CreateFirstPage('A')
133  if not self.parsedSource:
134  self.parsedSource = self.GetNsC()
135 
136  for i in self.parsedSource.keys():
137  print i, "is ok..."
138  self.WritePage("%s%s.html" % (self.prefix, i), self.CreatePage(i, self.parsedSource[i]))
139 
140  def CreateFirstPage(self, letter):
141  if not self.parsedSource:
142  self.parsedSource = self.GetNsC()
143  self.WritePage(self.fileName,
144  self.CreatePage(letter, self.parsedSource[letter]))
145 
146  def GetNsC(self):
147  content = self.GetContent()
148  bs = BeautifulSoup(content)
149 
150  tr = bs.findAll("tr", {})
151  data = {}
152  path = {}
153 
154  #Structure of data variable:
155  # {letter:[(link, ::name, info), ...]}
156  #Example:
157  # {'G':[
158  # (grEng.html, 'GraphicEngine', ''),
159  # (grEngTerra.html, 'GraphicEngine::TerrainGenarator', ''),
160  # (grEngTerraGVC.html, 'GraphicEngine::TerrainGenarator::GetVerticesCount', ''),
161  # ],
162  # 'H':[...]
163  # }
164 
165  #Structure of path variable:
166  # {depth:node}
167  #Example:
168  # {0:'GraphicEngine',
169  # 1:'GraphicEngine::TerrainGenarator',
170  # 2:'GraphicEngine::TerrainGenarator::GetVerticesCount'}
171  for i in tr:
172  if self.__GetDepth(i) == 0:
173  path = {0:self.__GetName(i)}
174  else:
175  path[self.__GetDepth(i)] = path[self.__GetDepth(i) - 1] + "::" + self.__GetName(i)
176 
177  if self.__IsLink(i):
178  if not path[self.__GetDepth(i)][0].upper() in self.List:
179  self.List = self.List + (path[self.__GetDepth(i)][0].upper(), )
180  data[path[self.__GetDepth(i)][0].upper()] = []
181 
182  if not self.__GetName(i).upper()[0] in self.List:
183  data[self.__GetName(i)[0].upper()] = []
184 
185  if path[self.__GetDepth(i)] != self.__GetName(i):
186  data[path[self.__GetDepth(i)][0].upper()].append((self.__GetLink(i),
187  path[self.__GetDepth(i)],
188  self.__GetInfo(i)))
189  data[self.__GetName(i)[0].upper()].append((self.__GetLink(i),
190  self.__GetName(i),
191  self.__GetInfo(i)))
192 
193  return data
194 
195 if len(sys.argv) > 3:
196  path = sys.argv[1]
197  file = sys.argv[2]
198  prefix = sys.argv[3]
199  s = Splitter(path, file, prefix)
200  print "pages are creating..."
201  s.CreatePages()
202 else:
203  print "Not enough parameters: file.py PATH FILE PREFIX"
204  print "Example: python Splitter.py CMSSW/doc/html/ annotated.html annotated_"
Splitter class is used for splitting class and namespace web pages to reduce access time...
Definition: Splitter.py:5
if(dp >Float(M_PI)) dp-