CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConfigFiles.py
Go to the documentation of this file.
1 from BeautifulSoup import *
2 import copy, sys
3 
4 ## ConfigFiles class is used for generating 'config files' html page.
5 class ConfigFiles:
6  ## Constructor method.
7  # @param path is the reference manual directory path and it is used as destination and source.
8  # @param outputFile is output file name. It should be "configfiles.html" for backward compatibility.
9  # @param prefix is used for file naming as prefix.
10  def __init__(self, path, outputFile, prefix = "configfilesList_"):
11  self.path = path
12  self.outputFile = outputFile
13  self.prefix = prefix
14  self.keywords = ["_cff", "_cfi", "_cfg"]
15  self.NSSource = self.ReadFile('namespaces.html')
16  self.tableStamp = '$TABLE$'
17  self.navBarStamp = '$NAVBAR$'
18  self.Template = None
19 
20  self.data = {}
21 
22  def ReadFile(self, fileName, pathFlag = True):
23  """This method reads file directly or from path."""
24  if pathFlag:
25  print "Read:", self.path + fileName
26  f = open(self.path + fileName)
27  else:
28  f = open(os.path.split(__file__)[0] + '/' + fileName)
29  print "Read:", fileName
30  data = f.read()
31  f.close()
32  return data
33 
34  def WriteFile(self, fileName, data):
35  """This method writes data"""
36  print "Write:", self.path + fileName
37  f = open(self.path + fileName, "w")
38  f.write(data)
39  f.close()
40 
41  def CreateTemplate(self):
42  self.Template = copy.deepcopy(self.NSSource)
43  soup = BeautifulSoup(self.Template)
44  contents = soup.find("div", { "class" : "contents" })
45  navBar = soup.find("div", { "id" : "navrow2", "class" : "tabs2"})
46  for child in contents.findChildren():
47  child.extract()
48  contents.insert(0, self.tableStamp)
49  navBar.insert(len(navBar), self.navBarStamp)
50  self.Template = str(soup)
51  print "Template created..."
52 
53  def Check(self, str_):
54  for i in self.keywords:
55  if i in str_:
56  return True
57  return False
58 
59  def PrepareData(self):
60 
61  soup = BeautifulSoup(self.NSSource)
62  contents = soup.find("div", { "class" : "contents" })
63  td = contents.findAll("td", {})
64 
65  parsedITemCounter = 0
66  for i in td:
67  if i.a and self.Check(i.a.text):
68  if not self.data.has_key(i.a.text[0].upper()):
69  self.data[i.a.text[0].upper()] = {}
70  self.data[i.a.text[0].upper()][i.a.text] = i.a["href"]
71  parsedITemCounter += 1
72  print "Config files parsed(%d)..." % parsedITemCounter
73 
74  def CreateTab(self, current):
75  tabHTML = '<div class="tabs3">\n<ul class="tablist">\n'
76  keys = self.data.keys()
77  keys.sort()
78  for i in keys:
79  if current == i:
80  tabHTML += '<li class="current"><a href="%s"><span>%s</span></a></li>\n' % ('#', i)
81  else:
82  tabHTML += '<li><a href="%s"><span>%s</span></a></li>\n' % (self.FileName(i), i)
83  tabHTML += '</ul>\n</div>\n'
84  return tabHTML
85 
86  def CreateTable(self, current):
87  tableHTML = '<table width="100%">\n<tbody>\n'
88  for i in self.data[current].keys():
89  tableHTML += '<tr><td class="indexkey"><a class="el" href="%s"> %s </a></td><td class="indexvalue"></td></tr>' % (self.data[current][i], i)
90  tableHTML += '</tbody>\n</table>\n'
91  return tableHTML
92 
93  def FileName(self, current):
94  return self.prefix + current + ".html"
95 
97  self.PrepareData()
98  self.CreateTemplate()
99 
100  keys = self.data.keys()
101  keys.sort()
102 
103  for i in keys:
104  page = self.Template.replace(self.navBarStamp, self.CreateTab(i)).replace(self.tableStamp, self.CreateTable(i))
105  self.WriteFile(self.FileName(i), page)
106  if i == 'A': self.WriteFile('configfiles.html', page)
107 
108 
109 if len(sys.argv) == 3:
110  PATH = sys.argv[1]
111  OUTF = sys.argv[2]
112 
113  l = ConfigFiles(PATH, OUTF)
114 
115  l.CreateConfigFilePage()
116 else:
117  print "parameter error. It must be like this: python ConfigFiles.py CMSSW/doc/html/ output.html"
def __init__
Constructor method.
Definition: ConfigFiles.py:10
ConfigFiles class is used for generating &#39;config files&#39; html page.
Definition: ConfigFiles.py:5