00001 '''
00002 Created on Aug 29, 2011
00003
00004 @author: MantYdze
00005 '''
00006
00007 errorOnImport = False
00008
00009 import sys
00010
00011 try:
00012 import urllib2, os, json
00013 except:
00014 errorOnImport = True
00015
00016 cvsBaseUrl = "http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW"
00017 baseUrl = "/cmsdoxygen/"
00018 refmanfiles = {}
00019 packageDocLinks = []
00020
00021
00022 def parseJSON(url):
00023 return json.loads(urllib2.urlopen(url).read())
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 def prepareRefManFiles(DOC_DIR):
00044 output = os.popen("find "+DOC_DIR+" -wholename '*/class*.html' -not \( -name '*-members.html' \) -print")
00045 lines = output.read().split("\n")
00046 output.close()
00047
00048 for line in lines:
00049 (head, tail) = os.path.split(line)
00050 refmanfiles[tail.replace("class","").replace(".html","")] = baseUrl+line[line.find(CMSSW_VERSION):]
00051
00052
00053 def preparePackageDocumentationLinks(DOC_DIR):
00054 source = open(DOC_DIR+"/pages.html", "r")
00055 lines = source.read().split("\n")
00056 source.close()
00057
00058 for line in lines:
00059 if (line.find("li><a class=\"el\" href=\"") != -1):
00060 packageDocLinks.append(line.split("\"")[3])
00061
00062
00063 def formatCVSLink(package, subpackage):
00064 cvsLink = "[ <a target=\"_blank\" href=\""+cvsBaseUrl+"/"+package+"/"+subpackage+"\">cvs</a> ]"
00065 return cvsLink
00066
00067 def formatPackageDocumentationLink(package, subpackage):
00068 for link in packageDocLinks:
00069 if (link.find(package+"_"+subpackage+".html") != -1):
00070 return "[ <a target=\"_blank\" href=\"../"+link+"\">packageDoc</a> ]"
00071
00072 return ""
00073
00074
00075 def generateTree(release):
00076
00077 data = parseJSON('/cmsdoxygen/tcproxy.php?type=packages&release=' + release)
00078
00079 tree = {}
00080 subsystems = sorted(data.keys())
00081
00082 for subsystem in subsystems:
00083 tree[subsystem] = {}
00084 for packagesub in data[subsystem]:
00085 (package, subpackage) = packagesub.split("/")
00086
00087 if not package in tree[subsystem]:
00088 tree[subsystem][package] = []
00089 tree[subsystem][package].append(subpackage)
00090
00091 return (tree, subsystems)
00092
00093
00094 def generateLeavesHTML(SRC_DIR, package, subpackage):
00095 html = ""
00096 try:
00097 dirList=os.listdir(SRC_DIR + "/" + package+"/"+subpackage+"/interface/")
00098 for classfile in dirList:
00099 if classfile.endswith(".h"):
00100 classfile = classfile.replace(".h", "")
00101 for key in refmanfiles.keys():
00102 if (key.find(classfile) != -1):
00103 classfile = "<a target=\"_blank\" href=\""+refmanfiles[key]+"\">"+classfile+"</a>"
00104 break
00105
00106 html += "<li>"+classfile+"</li>"
00107 except:
00108 pass
00109
00110 if html != "":
00111 html = "<ul>"+html+"</ul>"
00112
00113 return html
00114
00115
00116 def generateBranchHTML(SRC_DIR, tree, branch):
00117 branchHTML = ""
00118
00119 for package,subpackages in sorted(tree[branch].items()):
00120 branchHTML += "<li><span><strong>"+package+"</strong></span><ul>"
00121
00122 for subpackage in subpackages:
00123 branchHTML += "<li>"+subpackage + " "+ formatCVSLink(package, subpackage) + " " + formatPackageDocumentationLink(package, subpackage)
00124 branchHTML += generateLeavesHTML(SRC_DIR, package, subpackage)
00125 branchHTML+="</li>"
00126
00127 branchHTML +="</ul>"
00128
00129 branchHTML += "</li>"
00130 return branchHTML
00131
00132
00133 def loadTemplates():
00134 templateFile = SCRIPTS_LOCATION+"/indexPage/tree_template.html"
00135
00136 fileIN = open(templateFile, "r")
00137 treeTemplateHTML = fileIN.read()
00138 fileIN.close()
00139
00140
00141 templateFile = SCRIPTS_LOCATION+"/indexPage/indexpage_template.html"
00142 fileIN = open(templateFile, "r")
00143 indexPageTemplateHTML = fileIN.read()
00144 fileIN.close()
00145
00146
00147 return treeTemplateHTML, indexPageTemplateHTML
00148
00149 if len(sys.argv) < 3:
00150 print "Not enough arguments, try script.py CMSSW_VERSION PROJECT_LOCATION SCRIPT_LOCATION"
00151 sys.exit()
00152
00153 CMSSW_VERSION = sys.argv[1]
00154 PROJECT_LOCATION = sys.argv[2]
00155 SCRIPTS_LOCATION = sys.argv[3]
00156
00157 SRC_DIR = PROJECT_LOCATION+"/src"
00158
00159 try:
00160
00161 (treeTemplateHTML, indexPageTemplate) = loadTemplates()
00162 prepareRefManFiles(PROJECT_LOCATION+"/doc/html")
00163 preparePackageDocumentationLinks(PROJECT_LOCATION+"/doc/html")
00164 (tree, subsystems) = generateTree(CMSSW_VERSION)
00165
00166
00167
00168
00169
00170 managers = parseJSON('/cmsdoxygen/tcproxy.php?type=managers')
00171 users = parseJSON('/cmsdoxygen/tcproxy.php?type=users')
00172
00173 except:
00174
00175 fileIN = open(SCRIPTS_LOCATION+"/indexPage/indexpage_warning.html", "r")
00176 indexPageTemplateHTML = fileIN.read()
00177 fileIN.close()
00178 reason = "Failed during preparing treeview. "
00179 if errorOnImport:
00180 reason += " Error on import"
00181 output = open(PROJECT_LOCATION+"/doc/html/index.html", "w")
00182 output.write(indexPageTemplateHTML.replace("@CMSSW_VERSION@", CMSSW_VERSION).replace("@REASON@", reason))
00183 output.close()
00184 sys.exit(0)
00185
00186
00187 indexPageHTML = ""
00188 indexPageRowCounter = 0
00189 indexPageBlock = """
00190 <tr class=\"@ROW_CLASS@\">
00191 <td width=\"50%\"><a href=\"#@SUBSYSTEM@\" onclick=\"javascript:getIframe('@SUBSYSTEM@')\">@SUBSYSTEM@</a></td>
00192 <td width=\"50%\" class=\"contact\">@CONTACTS@</td>
00193 </tr>
00194 <tr><td colspan=\"2\"><span id=\"@SUBSYSTEM@\"></span></td></tr>
00195 """
00196
00197 indexPageBlockNoTree = """
00198 <tr class=\"@ROW_CLASS@\">
00199 <td width=\"50%\">@SUBSYSTEM@</td>
00200 <td width=\"50%\" class=\"contact\">@CONTACTS@</td>
00201 </tr>
00202 <tr><td colspan=\"2\"><span id=\"@SUBSYSTEM@\"></span></td></tr>
00203 """
00204
00205
00206 map = {}
00207 map["Full Simulation"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideSimulation"
00208 map["Generators"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideEventGeneration"
00209 map["Fast Simulation"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideFastSimulation"
00210 map["L1"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideL1Trigger"
00211 map["HLT"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideHighLevelTrigger"
00212 map["Reconstruction"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideReco"
00213 map["Core"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideFrameWork"
00214 map["DQM"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideDQM"
00215 map["Database"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCondDB"
00216 map["Calibration and Alignment"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCalAli"
00217 map["Analysis"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCrab"
00218 map["Geometry"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideDetectorDescription"
00219 map["DAQ"] = "https://twiki.cern.ch/twiki/bin/view/CMS/TriDASWikiHome"
00220 map["Visualization"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideVisualization"
00221 map["Documentation"] = "https://twiki.cern.ch/twiki/bin/view/CMS/SWGuide"
00222
00223
00224
00225
00226 for subsystem in subsystems:
00227 print subsystem
00228 branchHTML = generateBranchHTML(SRC_DIR, tree, subsystem)
00229
00230 treeHTML = treeTemplateHTML.replace("@TREE@", branchHTML).replace("@SUBSYSTEM@", subsystem).replace("@CMSSW_VERSION@", CMSSW_VERSION)
00231
00232
00233 block = indexPageBlockNoTree
00234 if (map.has_key(subsystem)):
00235 block = indexPageBlock
00236 treeHTML = treeHTML.replace("@LINK_TO_TWIKI@", map[subsystem])
00237
00238
00239 contacts = ""
00240 for manager in managers[subsystem]:
00241 if (contacts != ""):
00242 contacts += ", "
00243 contacts += "<a href=\"mailto:"+users[manager][1]+"\">" + users[manager][0] + "</a>"
00244
00245
00246 if indexPageRowCounter % 2 == 0:
00247 rowCssClass = "odd"
00248 else:
00249 rowCssClass = "even"
00250
00251 indexPageHTML += block.replace("@CONTACTS@", contacts).replace("@SUBSYSTEM@", subsystem).replace("@ROW_CLASS@", rowCssClass)
00252
00253 output = open(PROJECT_LOCATION+"/doc/html/splittedTree/"+subsystem+".html", "w")
00254 output.write(treeHTML)
00255 output.close()
00256
00257 indexPageHTML = indexPageTemplate.replace("@TREE_BLOCKS@", indexPageHTML).replace("@CMSSW_VERSION@", CMSSW_VERSION)
00258 output = open(PROJECT_LOCATION+"/doc/html/index.html", "w")
00259 output.write(indexPageHTML)
00260 output.close()