CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Documentation/ReferenceManualScripts/doxygen/utils/indexPage/Association.py

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