CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
packageDocSplitter.py
Go to the documentation of this file.
1 '''
2 Created on Oct 27, 2011
3 
4 @author: MantYdze
5 '''
6 import sys
7 from BeautifulSoup import BeautifulSoup, NavigableString
8 
9 SUBSYSTEMS = {}
10 TAGLIST = {}
11 
12 def parseTagList(tagList):
13  input = open(tagList, "r")
14  source = input.read()
15  input.close()
16  lines = source.split("\n")
17 
18  for line in lines[4:-3]:
19  items = line.strip().split(" ")
20  package = items[0]
21  tag = items[-1]
22  TAGLIST[package] = tag
23 
24 def addTagToPackageDoc(line, subsystem, package):
25  if (TAGLIST.has_key(subsystem+"/"+package)):
26  tag = TAGLIST[subsystem+"/"+package]
27 
28  path = line[line.find("href=\"")+6:line.find("\">")]
29 
30  input = open(PROJECT_PATH+path, "r")
31  source = input.read()
32  input.close()
33 
34  output = open(PROJECT_PATH+path, "w")
35  output.write(source.replace("@CVS_TAG@", tag).replace("Source code (CVS tag: @)", "Source code (CVS tag: "+tag+" )"))
36  output.close()
37 
38 def extractList(filename):
39  input = open(filename, "r")
40  source = input.read()
41  input.close()
42 
43  header = ""
44  headerFull = False
45  footer = ""
46  footerStarted = False
47 
48  lines = source.split("\n")
49 
50  for line in lines:
51 
52  if (line.find("<li><a class=\"el\"") != -1) and (line.find("Package ") != -1):
53  headerFull = True
54  title = line[line.find("Package ")+8:-4]
55  subsystem = title.split("/")[0]
56  package = "/".join(title.split("/")[1:])
57  if not SUBSYSTEMS.has_key(subsystem):
58  SUBSYSTEMS[subsystem] = {}
59  SUBSYSTEMS[subsystem][package] = line.replace("<li>","")
60 
61  addTagToPackageDoc(line, subsystem, package)
62 
63  if not headerFull:
64  header += line+"\n"
65 
66  if line.find("<hr class=\"footer\"/>") != -1:
67  footerStarted = True
68 
69  if footerStarted:
70  footer += line+"\n"
71 
72  return header, footer, source
73 
74 
75 def addMenuToHeader(header, subsys):
76  menu = "<div class=\"tabs3\">\n"
77  menu += "<ul class=\"tablist\">\n"
78 
79  for subsystem in sorted(SUBSYSTEMS.keys()):
80  current = ""
81  if subsystem == subsys:
82  current = " class=\"current\""
83  menu += "<li"+current+"><a href=\"packageDocumentation_"+subsystem+".html\"><span>"+subsystem+"</span></a></li>\n"
84 
85  menu += "</ul>\n"
86  menu += "</div>\n"
87 
88  soap = BeautifulSoup(header)
89  div = soap.find("div", {"class":"tabs"})
90 
91  div.append(NavigableString(menu))
92 
93  return soap.renderContents()
94 
95 def createHTMLFiles(header, footer, PROJECT_PATH):
96  for subsystem in sorted(SUBSYSTEMS.keys()):
97  html = addMenuToHeader(header, subsystem)
98  html += "<ul>"
99 
100  for package in sorted(SUBSYSTEMS[subsystem].keys()):
101  html+="<li>"+SUBSYSTEMS[subsystem][package]+"</li>"
102  html+="</ul>"
103 
104  output = open(PROJECT_PATH+"packageDocumentation_"+subsystem+".html", "w")
105  output.write(html)
106  output.close()
107 
108 
109 if len(sys.argv) == 4:
110  filename = sys.argv[1]
111  PROJECT_PATH = sys.argv[2]+"/doc/html/"
112  tagList = sys.argv[2]+"/"+sys.argv[3]
113  parseTagList(tagList)
114  (header, footer, html) = extractList(PROJECT_PATH+filename)
115  createHTMLFiles(header, footer, PROJECT_PATH)
116 
117  html = addMenuToHeader(html, "")
118  output = open(PROJECT_PATH+filename, "w")
119  output.write(html)
120  output.close()
121 else:
122  print "not enough parameters"
123  print "#1 package documentation file (html) to split by subsystems"
124  print "#2 path to buildarea (must end with CMSSW_x_y_y)"
125  print "#3 list generated by showtags -t"
126  print "i.e. pages.html /data/refman/CMSSW_5_0_0 tagList.txt"
127 
128 
129 
130 
131 
132 
133 
def replace
Definition: linker.py:10
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
double split
Definition: MVATrainer.cc:139