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