CMS 3D CMS Logo

Functions | Variables

splitter Namespace Reference

Functions

def appendLinkToList
def backupOriginal
def createHtmlPages
def createMenu
def extractLinks
def getFooter
def getHeader

Variables

dictionary INDEX = {}
list LINKS = []
list PREFIX = sys.argv[3]
list PROJECT_LOCATION = sys.argv[1]
list sourceFile = PROJECT_LOCATION+sys.argv[2]

Detailed Description

Created on Nov 9, 2010
Updated on Oct 19, 2011

@author: Mantas Stankevicius

Function Documentation

def splitter::appendLinkToList (   line,
  letter 
)

Definition at line 100 of file splitter.py.

00101                                   :
00102     if (not INDEX.has_key(letter)):
00103         subList = [letter, line]
00104         LINKS.append(subList)
00105         INDEX[letter] = letter
00106     else:
00107         for l in LINKS:
00108             if l[0] == letter:
00109                 l.append(line)
00110     

def splitter::backupOriginal ( )

Definition at line 172 of file splitter.py.

00173                     :
00174     fh = open(sourceFile,'r')
00175     html = fh.read()
00176     fh.close()
00177 
00178         
00179     soap = BeautifulSoup(html)
00180     div = soap.find("div", {"class":"tabs2"})
00181     # Adding menu of letters at the end of navigation bar
00182     text = NavigableString(createMenu("All"))
00183     div.append(text)
00184 #    div.insert(div.__len__(), createMenu("All"))
00185     
00186     html = soap.renderContents()
00187     
00188     output = open(PROJECT_LOCATION+"/doc/html/"+PREFIX+"All.html", "w")
00189     output.write(html)
00190     output.close() 

def splitter::createHtmlPages ( )

Definition at line 135 of file splitter.py.

00136                      :
00137     
00138     HTMLHeader = getHeader()
00139     HTMLFooter = getFooter()
00140     
00141     for list in LINKS:
00142         letter = list[0]
00143         
00144         html = HTMLHeader
00145         
00146         for item in list[1:]:
00147             html += item+"\n"
00148         
00149         html += HTMLFooter
00150         
00151         soap = BeautifulSoup(html)
00152         div = soap.find("div", {"class":"tabs2"})
00153 
00154         text = NavigableString(createMenu(letter))
00155         div.append(text)
00156 
00157 #        div.insert(div.__len__(), createMenu(letter))
00158         
00159         html = soap.renderContents()
00160         
00161         path = PROJECT_LOCATION+"/doc/html/"+PREFIX+letter+".html"
00162         output = open(path, "w")
00163         output.write(html)
00164         output.close()
00165         
00166         if letter == "A":
00167             output = open(sourceFile, "w")
00168             output.write(html)
00169             output.close()  
00170         
00171         print PROJECT_LOCATION+"/doc/html/"+PREFIX+letter+".html    Done!"                  

def splitter::createMenu (   letter)

Definition at line 111 of file splitter.py.

00112                       :
00113     html  = "<div class=\"tabs3\">\n"
00114     html += "<ul class=\"tablist\">\n"
00115 
00116     letters = []
00117     for i in INDEX:
00118         letters.append(i)
00119     
00120     letters.sort()
00121     letters.append("All")
00122     
00123     for l in letters:
00124         c = l
00125         current = ""
00126         if c == letter:
00127             current = " class=\"current\""
00128             
00129         html += "<li"+current+"><a href=\""+PREFIX+c+".html\"><span>"+c+"</span></a></li>\n"
00130     
00131     html += "</ul>\n"
00132     html += "</div>\n"
00133     
00134     return html

def splitter::extractLinks ( )
Extracts links from source file 
    from <div class = 'contents'> </div>

Definition at line 67 of file splitter.py.

00068                   :
00069     """ Extracts links from source file 
00070         from <div class = 'contents'> </div>"""
00071         
00072     fh = open(sourceFile,'r')
00073     source = fh.read()
00074     fh.close()
00075     
00076     soup = BeautifulSoup(source)
00077     div = soup.find("div", {"class":"contents"})
00078     
00079     if (div != None):
00080         content = div.renderContents()
00081     
00082     lines = content.split("\n")
00083     for line in lines:
00084         if (line.find("<tr>") != -1):
00085             
00086             indexFrom = line.rfind(".html\">") + 7
00087             indexTo = line.rfind("</a>")
00088             linkText = line[indexFrom:indexTo]
00089             
00090             linkTextParts = linkText.split("::")
00091             
00092             if len(linkTextParts) == 2:
00093                 tmpLine = line.replace(linkText, linkTextParts[1])
00094                 letter = linkTextParts[1][0].upper()
00095                 appendLinkToList(tmpLine, letter)
00096 
00097             letter = linkText[0].upper()
00098             appendLinkToList(line, letter)
00099             

def splitter::getFooter ( )
Reading source file from end until </table>. 
    After </table> begins list of links (reading from end) 

Definition at line 43 of file splitter.py.

00044                :
00045     """ Reading source file from end until </table>. 
00046         After </table> begins list of links (reading from end) 
00047     """
00048     fh = open(sourceFile,'r')
00049     source = fh.read()
00050     fh.close()
00051     
00052     lines = source.split("\n")
00053     lines.reverse()
00054     
00055     html = []
00056     enough = False
00057     
00058     for line in lines:
00059         if (not enough):
00060             html.append(line)
00061             
00062         if line.find("</table>") != -1:
00063             enough = True
00064         
00065     html.reverse()            
00066     return "\n".join(html)   

def splitter::getHeader ( )
Reading source file until <table>. 
    After <table> begins list of links 

Definition at line 20 of file splitter.py.

00021                :
00022     """ Reading source file until <table>. 
00023         After <table> begins list of links 
00024     """
00025     fh = open(sourceFile,'r')
00026     source = fh.read()
00027     fh.close()
00028     
00029     lines = source.split("\n")
00030 
00031     html = []
00032     enough = False
00033     
00034     for line in lines:
00035         if line.find("<table>") != -1:
00036             enough = True
00037             
00038         if (not enough):
00039             html.append(line)
00040             
00041     html.append("<table width=\"100%\">")
00042     return "\n".join(html)


Variable Documentation

dictionary splitter::INDEX = {}

Definition at line 11 of file splitter.py.

list splitter::LINKS = []

Definition at line 14 of file splitter.py.

list splitter::PREFIX = sys.argv[3]

Definition at line 197 of file splitter.py.

list splitter::PROJECT_LOCATION = sys.argv[1]

Definition at line 193 of file splitter.py.

Definition at line 195 of file splitter.py.