SEESenv/scripts/finalhtml.py
changeset 45 b5bff924ef69
parent 44 d0e9b52bda73
child 49 3b5f1341d6c6
equal deleted inserted replaced
44:d0e9b52bda73 45:b5bff924ef69
    10 
    10 
    11 repo='/home/hg/repos/SEES-hacks/temp/'
    11 repo='/home/hg/repos/SEES-hacks/temp/'
    12 #repo='/home/amit/testdocbook2/'
    12 #repo='/home/amit/testdocbook2/'
    13 
    13 
    14 def sort_doubledigit(chapter_names):
    14 def sort_doubledigit(chapter_names):
       
    15     extend_list=[]
    15     for item in chapter_names:
    16     for item in chapter_names:
    16         reg_obj=re.compile(os.path.join(repo,'ch1[0-9].*.html'))
    17         reg_obj=re.compile(os.path.join(repo,'ch1[0-9].*.html'))
    17         if (reg_obj.match(item)):
    18         if (reg_obj.match(item)):
    18             item_tmp=item
    19             item=re.sub('ch1','chn1',item)
    19             chapter_names.remove(item)
    20             extend_list.append(item)
    20             chapter_names.append(item_tmp)
    21     chapter_names=chapter_names[len(extend_list):]    
       
    22     chapter_names.extend(extend_list)
       
    23 
    21     return chapter_names
    24     return chapter_names
       
    25 
       
    26 
       
    27 
       
    28 
    22 
    29 
    23 def finalchanges(file_name,html_string):
    30 def finalchanges(file_name,html_string):
    24     """some of the final changes that need to do be done on the html before creating the final usable page in the hgbook project"""	    
    31     """some of the final changes that need to do be done on the html before creating the final usable page in the hgbook project"""	    
    25 #    print html_string    
    32 #    print html_string    
    26     replace_string="""<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Chapter 2. Basic Python</title><link rel="stylesheet" href="/review/support/styles.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.74.3"><link rel="shortcut icon" type="image/png" href="/review/support/figs/favicon.png"><script type="text/javascript" src="/review/support/jquery-min.js"></script><script type="text/javascript" src="/review/support/form.js"></script><script type="text/javascript" src="/review/support/hsbook.js"></script></head>"""
    33     replace_string="""<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Chapter 2. Basic Python</title><link rel="stylesheet" href="/review/support/styles.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.74.3"><link rel="shortcut icon" type="image/png" href="/review/support/figs/favicon.png"><script type="text/javascript" src="/review/support/jquery-min.js"></script><script type="text/javascript" src="/review/support/form.js"></script><script type="text/javascript" src="/review/support/hsbook.js"></script></head>"""
    31 #    print chapter_names_sorted
    38 #    print chapter_names_sorted
    32     chapter_names_sorted=sort_doubledigit(chapter_names_sorted)
    39     chapter_names_sorted=sort_doubledigit(chapter_names_sorted)
    33     chapter_names=chapter_names_sorted
    40     chapter_names=chapter_names_sorted
    34     previous_string='<<<'
    41     previous_string='<<<'
    35     next_string='>>>'
    42     next_string='>>>'
    36     html_src_folder="review/html/"
    43     ch_name_tmp=file_name.split('.')[0]
    37     current_chapter_index=chapter_names.index(file_name)
    44 #    html_src_folder=""
       
    45     
    38 
    46 
    39     current_chapter=os.path.join(html_src_folder,chapter_names[current_chapter_index].split('/')[-1])
    47     try:
    40     if (current_chapter_index-1>0):
    48     #Handling the problem of chapter names in two digits
    41         previous_chapter=os.path.join(html_src_folder,chapter_names[current_chapter_index-1].split('/')[-1])
    49         current_chapter_index=chapter_names.index(file_name)
       
    50     except :
       
    51         temp_file_name=re.sub('ch1','chn1',file_name)
       
    52         current_chapter_index=chapter_names.index(temp_file_name)
       
    53 
       
    54 
       
    55 
       
    56     current_chapter=chapter_names[current_chapter_index].split('/')[-1]
       
    57     if (current_chapter_index-1>=0):
       
    58         previous_chapter=chapter_names[current_chapter_index-1].split('/')[-1]
    42     else:
    59     else:
    43         previous_chapter=''
    60         previous_chapter=''
    44         previous_string=''
    61         previous_string=''
    45     try :  
    62     try :  
    46         next_chapter=os.path.join(html_src_folder,chapter_names[current_chapter_index+1].split('/')[-1])
    63         next_chapter=chapter_names[current_chapter_index+1].split('/')[-1]
    47     except:
    64     except:
    48         next_string=''
    65         next_string=''
    49         next_chapter=''
    66         next_chapter=''
    50     
    67     
    51     ch_name_tmp=file_name.split('.')[0]
    68     
    52     chapter_xml=ch_name_tmp+'.xml'
    69     chapter_xml=ch_name_tmp+'.xml'
    53        
    70        
    54 
    71 
    55     try:    
    72     try:    
    56         xml_file =open(chapter_xml,'r').read()
    73         xml_file =open(chapter_xml,'r').read()
    68 #        soup.html.body.insert(0,NavigableString(body_add_string))
    85 #        soup.html.body.insert(0,NavigableString(body_add_string))
    69 
    86 
    70 
    87 
    71     except :
    88     except :
    72         ch_title=re.split('[0-9]*',ch_name)[1]    
    89         ch_title=re.split('[0-9]*',ch_name)[1]    
    73         title_string='Chapter. '+ ch_title
    90         title_string=ch_title
    74         current_chapter_title=title_string        
    91         current_chapter_title=title_string        
    75     
    92     
    76     
    93     
    77 
    94 
    78     body_add_string="""<div><table width="100%%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter %s</th></tr><tr><td width="20%%" align="left"><a accesskey="p" href="%s">%s</a></td><th width="60%%" align="center"> </th><td width="20%%" align="right"> <a accesskey="n" href="%s">%s</a></td></tr></table></div>"""%(current_chapter_title,previous_chapter,previous_string,next_chapter,next_string)
    95     body_add_string="""<div><table width="100%%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter %s</th></tr><tr><td width="20%%" align="left"><a accesskey="p" href="%s">%s</a></td><th width="60%%" align="center"> </th><td width="20%%" align="right"> <a accesskey="n" href="%s">%s</a></td></tr></table></div>"""%(current_chapter_title,previous_chapter,previous_string,next_chapter,next_string)