CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Association.py
Go to the documentation of this file.
1 '''
2 Created on Aug 29, 2011
3 
4 @author: MantYdze
5 '''
6 
7 errorOnImport = False
8 
9 import sys
10 
11 try:
12  import urllib2, os, json
13 except:
14  errorOnImport = True
15 
16 cvsBaseUrl = "http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW" # NO SLASH IN THE END
17 baseUrl = "/cmsdoxygen/"
18 refmanfiles = {}
19 packageDocLinks = []
20 
21 
22 def parseJSON(url):
23  ret = {}
24 
25  html = os.popen("curl \""+url+"\"")
26  input = html.read()
27  html.close()
28 
29  return json.loads(html)
30 
31 
32 ## Prepate dictionary of doxygen generated html files
33 def prepareRefManFiles(DOC_DIR):
34  output = os.popen("find "+DOC_DIR+" -wholename '*/class*.html' -not \( -name '*-members.html' \) -print")
35  lines = output.read().split("\n")
36  output.close()
37 
38  for line in lines:
39  (head, tail) = os.path.split(line)
40  refmanfiles[tail.replace("class","").replace(".html","")] = baseUrl+line[line.find(CMSSW_VERSION):]
41 
42 ## Extract links to package documentation
44  source = open(DOC_DIR+"/pages.html", "r")
45  lines = source.read().split("\n")
46  source.close()
47 
48  for line in lines:
49  if (line.find("li><a class=\"el\" href=\"") != -1):
50  packageDocLinks.append(line.split("\"")[3])
51 
52 ## Format CVS link
53 def formatCVSLink(package, subpackage):
54  cvsLink = "[ <a target=\"_blank\" href=\""+cvsBaseUrl+"/"+package+"/"+subpackage+"\">cvs</a> ]"
55  return cvsLink
56 
57 def formatPackageDocumentationLink(package, subpackage):
58  for link in packageDocLinks:
59  if (link.find(package+"_"+subpackage+".html") != -1):
60  return "[ <a target=\"_blank\" href=\"../"+link+"\">packageDoc</a> ]"
61 
62  return ""
63 
64 ## Fetches information about Subsystems/Packages/Subpackages from TagCollector
65 def generateTree(release):
66  #data = json.loads(urllib2.urlopen('https://cmstags.cern.ch/tc/CategoriesPackagesJSON?release=' + release).read())
67  data = parseJSON('/cmsdoxygen/tcproxy.php?type=packages&release=' + release)
68 
69  tree = {}
70  subsystems = sorted(data.keys())
71 
72  for subsystem in subsystems:
73  tree[subsystem] = {}
74  for packagesub in data[subsystem]:
75  (package, subpackage) = packagesub.split("/")
76 
77  if not package in tree[subsystem]:
78  tree[subsystem][package] = []
79  tree[subsystem][package].append(subpackage)
80 
81  return (tree, subsystems)
82 
83 ## Generates HTML for subpackage
84 def generateLeavesHTML(SRC_DIR, package, subpackage):
85  html = ""
86  try:
87  dirList=os.listdir(SRC_DIR + "/" + package+"/"+subpackage+"/interface/")
88  for classfile in dirList:
89  if classfile.endswith(".h"):
90  classfile = classfile.replace(".h", "")
91  for key in refmanfiles.keys():
92  if (key.find(classfile) != -1):
93  classfile = "<a target=\"_blank\" href=\""+refmanfiles[key]+"\">"+classfile+"</a>"
94  break
95 
96  html += "<li>"+classfile+"</li>"
97  except:
98  pass
99 
100  if html != "":
101  html = "<ul>"+html+"</ul>"
102 
103  return html
104 
105 ## Generates HTML for Subsystem
106 def generateBranchHTML(SRC_DIR, tree, branch):
107  branchHTML = ""
108 
109  for package,subpackages in sorted(tree[branch].items()):
110  branchHTML += "<li><span><strong>"+package+"</strong></span><ul>"
111 
112  for subpackage in subpackages:
113  branchHTML += "<li>"+subpackage + " "+ formatCVSLink(package, subpackage) + " " + formatPackageDocumentationLink(package, subpackage)
114  branchHTML += generateLeavesHTML(SRC_DIR, package, subpackage)
115  branchHTML+="</li>"
116 
117  branchHTML +="</ul>"
118 
119  branchHTML += "</li>"
120  return branchHTML
121 
122 ## Read template file
124  templateFile = SCRIPTS_LOCATION+"/indexPage/tree_template.html"
125 
126  fileIN = open(templateFile, "r")
127  treeTemplateHTML = fileIN.read()
128  fileIN.close()
129 
130 
131  templateFile = SCRIPTS_LOCATION+"/indexPage/indexpage_template.html"
132  fileIN = open(templateFile, "r")
133  indexPageTemplateHTML = fileIN.read()
134  fileIN.close()
135 
136 
137  return treeTemplateHTML, indexPageTemplateHTML
138 
139 if len(sys.argv) < 3:
140  print "Not enough arguments, try script.py CMSSW_VERSION PROJECT_LOCATION SCRIPT_LOCATION"
141  sys.exit()
142 
143 CMSSW_VERSION = sys.argv[1]
144 PROJECT_LOCATION = sys.argv[2]
145 SCRIPTS_LOCATION = sys.argv[3]
146 
147 SRC_DIR = PROJECT_LOCATION+"/src"
148 
149 try:
150 # Tree Preparation
151  (treeTemplateHTML, indexPageTemplate) = loadTemplates()
152  prepareRefManFiles(PROJECT_LOCATION+"/doc/html")
153  preparePackageDocumentationLinks(PROJECT_LOCATION+"/doc/html")
154  (tree, subsystems) = generateTree(CMSSW_VERSION)
155 
156  ## Index Page Preparations
157 
158  # Loading responsibles for subsystems
159  #(managers, users) = json.loads(urllib2.urlopen('https://cmstags.cern.ch/tc/CategoriesManagersJSON').read())
160  managers = parseJSON('/cmsdoxygen/tcproxy.php?type=managers')
161  users = parseJSON('/cmsdoxygen/tcproxy.php?type=users')
162 
163 except:
164  ## Warning page
165  fileIN = open(SCRIPTS_LOCATION+"/indexPage/indexpage_warning.html", "r")
166  indexPageTemplateHTML = fileIN.read()
167  fileIN.close()
168  reason = "Failed during preparing treeview. "
169  if errorOnImport:
170  reason += " Error on import"
171  output = open(PROJECT_LOCATION+"/doc/html/index.html", "w")
172  output.write(indexPageTemplateHTML.replace("@CMSSW_VERSION@", CMSSW_VERSION).replace("@REASON@", reason))
173  output.close()
174  sys.exit(0)
175 
176 
177 indexPageHTML = ""
178 indexPageRowCounter = 0
179 indexPageBlock = """
180 <tr class=\"@ROW_CLASS@\">
181  <td width=\"50%\"><a href=\"#@SUBSYSTEM@\" onclick=\"javascript:getIframe('@SUBSYSTEM@')\">@SUBSYSTEM@</a></td>
182  <td width=\"50%\" class=\"contact\">@CONTACTS@</td>
183 </tr>
184 <tr><td colspan=\"2\"><span id=\"@SUBSYSTEM@\"></span></td></tr>
185 """
186 
187 indexPageBlockNoTree = """
188 <tr class=\"@ROW_CLASS@\">
189  <td width=\"50%\">@SUBSYSTEM@</td>
190  <td width=\"50%\" class=\"contact\">@CONTACTS@</td>
191 </tr>
192 <tr><td colspan=\"2\"><span id=\"@SUBSYSTEM@\"></span></td></tr>
193 """
194 
195 # Links to Twiki pages
196 map = {}
197 map["Full Simulation"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideSimulation"
198 map["Generators"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideEventGeneration"
199 map["Fast Simulation"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideFastSimulation"
200 map["L1"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideL1Trigger"
201 map["HLT"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHighLevelTrigger"
202 map["Reconstruction"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideReco"
203 map["Core"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideFrameWork"
204 map["DQM"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideDQM"
205 map["Database"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCondDB"
206 map["Calibration and Alignment"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCalAli"
207 map["Analysis"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCrab"
208 map["Geometry"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideDetectorDescription"
209 map["DAQ"] = "https://twiki.cern.ch/twiki/bin/view/CMS/TriDASWikiHome"
210 map["Visualization"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideVisualization"
211 map["Documentation"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuide"
212 
213 
214 
215 ## Generating treeviews
216 for subsystem in subsystems:
217  print subsystem
218  branchHTML = generateBranchHTML(SRC_DIR, tree, subsystem)
219 
220  treeHTML = treeTemplateHTML.replace("@TREE@", branchHTML).replace("@SUBSYSTEM@", subsystem).replace("@CMSSW_VERSION@", CMSSW_VERSION)
221 
222  ## Formating index page's pieces
223  block = indexPageBlockNoTree
224  if (map.has_key(subsystem)):
225  block = indexPageBlock
226  treeHTML = treeHTML.replace("@LINK_TO_TWIKI@", map[subsystem])
227 
228 
229  contacts = ""
230  for manager in managers[subsystem]:
231  if (contacts != ""):
232  contacts += ", "
233  contacts += "<a href=\"mailto:"+users[manager][1]+"\">" + users[manager][0] + "</a>"
234 
235 
236  if indexPageRowCounter % 2 == 0:
237  rowCssClass = "odd"
238  else:
239  rowCssClass = "even"
240 
241  indexPageHTML += block.replace("@CONTACTS@", contacts).replace("@SUBSYSTEM@", subsystem).replace("@ROW_CLASS@", rowCssClass)
242 
243  output = open(PROJECT_LOCATION+"/doc/html/splittedTree/"+subsystem+".html", "w")
244  output.write(treeHTML)
245  output.close()
246 
247 indexPageHTML = indexPageTemplate.replace("@TREE_BLOCKS@", indexPageHTML).replace("@CMSSW_VERSION@", CMSSW_VERSION)
248 output = open(PROJECT_LOCATION+"/doc/html/index.html", "w")
249 output.write(indexPageHTML)
250 output.close()
def generateLeavesHTML
Generates HTML for subpackage.
Definition: Association.py:84
def replace
Definition: linker.py:10
def preparePackageDocumentationLinks
Extract links to package documentation.
Definition: Association.py:43
def generateTree
Fetches information about Subsystems/Packages/Subpackages from TagCollector.
Definition: Association.py:65
def loadTemplates
Read template file.
Definition: Association.py:123
def prepareRefManFiles
Prepate dictionary of doxygen generated html files.
Definition: Association.py:33
def formatCVSLink
Format CVS link.
Definition: Association.py:53
def formatPackageDocumentationLink
Definition: Association.py:57
double split
Definition: MVATrainer.cc:139
def generateBranchHTML
Generates HTML for Subsystem.
Definition: Association.py:106