CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/Documentation/ReferenceManualScripts/doxygen/utils/splitter/packageDocSplitter.py

Go to the documentation of this file.
00001 '''
00002 Created on Oct 27, 2011
00003 
00004 @author: MantYdze
00005 '''
00006 import sys
00007 from BeautifulSoup import BeautifulSoup, NavigableString
00008 
00009 SUBSYSTEMS = {}
00010 TAGLIST = {}
00011 
00012 def parseTagList(tagList):
00013     input = open(tagList, "r")
00014     source = input.read()
00015     input.close()
00016     lines = source.split("\n")
00017     
00018     for line in lines[4:-3]:        
00019         items = line.strip().split(" ")
00020         package = items[0]
00021         tag = items[-1]
00022         TAGLIST[package] = tag
00023         
00024 def addTagToPackageDoc(line, subsystem, package):
00025     if (TAGLIST.has_key(subsystem+"/"+package)):
00026         tag = TAGLIST[subsystem+"/"+package]
00027     
00028         path = line[line.find("href=\"")+6:line.find("\">")]
00029         
00030         input = open(PROJECT_PATH+path, "r")
00031         source = input.read()
00032         input.close()
00033         
00034         output = open(PROJECT_PATH+path, "w")
00035         output.write(source.replace("@CVS_TAG@", tag).replace("Source code (CVS tag: @)", "Source code (CVS tag: "+tag+" )"))
00036         output.close()
00037 
00038 def extractList(filename):
00039     input = open(filename, "r")
00040     source = input.read()
00041     input.close()
00042     
00043     header = ""
00044     headerFull = False
00045     footer = ""
00046     footerStarted = False
00047     
00048     lines = source.split("\n")
00049     
00050     for line in lines:
00051                 
00052         if (line.find("<li><a class=\"el\"") != -1) and (line.find("Package ") != -1):
00053             headerFull = True
00054             title = line[line.find("Package ")+8:-4]
00055             subsystem = title.split("/")[0]
00056             package = "/".join(title.split("/")[1:])
00057             if not SUBSYSTEMS.has_key(subsystem):
00058                 SUBSYSTEMS[subsystem] = {}
00059             SUBSYSTEMS[subsystem][package] = line.replace("<li>","")
00060             
00061             addTagToPackageDoc(line, subsystem, package)
00062         
00063         if not headerFull:
00064             header += line+"\n"
00065         
00066         if line.find("<hr class=\"footer\"/>") != -1:
00067             footerStarted = True
00068         
00069         if footerStarted:
00070             footer += line+"\n"
00071 
00072     return header, footer, source
00073 
00074 
00075 def addMenuToHeader(header, subsys):
00076     menu  = "<div class=\"tabs3\">\n"
00077     menu += "<ul class=\"tablist\">\n"
00078     
00079     for subsystem in sorted(SUBSYSTEMS.keys()):
00080         current = ""
00081         if subsystem == subsys:
00082             current = " class=\"current\""
00083         menu += "<li"+current+"><a href=\"packageDocumentation_"+subsystem+".html\"><span>"+subsystem+"</span></a></li>\n"
00084     
00085     menu += "</ul>\n"
00086     menu += "</div>\n"
00087     
00088     soap = BeautifulSoup(header)
00089     div = soap.find("div", {"class":"tabs"})
00090     
00091     div.append(NavigableString(menu))
00092     
00093     return soap.renderContents()
00094     
00095 def createHTMLFiles(header, footer, PROJECT_PATH):
00096     for subsystem in sorted(SUBSYSTEMS.keys()):
00097         html = addMenuToHeader(header, subsystem)
00098         html += "<ul>"
00099         
00100         for package in sorted(SUBSYSTEMS[subsystem].keys()):
00101             html+="<li>"+SUBSYSTEMS[subsystem][package]+"</li>"
00102         html+="</ul>"
00103         
00104         output = open(PROJECT_PATH+"packageDocumentation_"+subsystem+".html", "w")
00105         output.write(html)
00106         output.close()
00107         
00108         
00109 if len(sys.argv) == 4:
00110     filename = sys.argv[1]
00111     PROJECT_PATH = sys.argv[2]+"/doc/html/"
00112     tagList = sys.argv[2]+"/"+sys.argv[3]
00113     parseTagList(tagList)
00114     (header, footer, html) = extractList(PROJECT_PATH+filename)
00115     createHTMLFiles(header, footer, PROJECT_PATH)
00116 
00117     html = addMenuToHeader(html, "")
00118     output = open(PROJECT_PATH+filename, "w")
00119     output.write(html)
00120     output.close()
00121 else:
00122     print "not enough parameters"
00123     print "#1 package documentation file (html) to split by subsystems"
00124     print "#2 path to buildarea (must end with CMSSW_x_y_y)"
00125     print "#3 list generated by showtags -t"
00126     print "i.e. pages.html /data/refman/CMSSW_5_0_0 tagList.txt"
00127 
00128 
00129 
00130 
00131 
00132 
00133