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