SEESenv/scripts/myrst2xml.py
author amit@thunder
Sun, 28 Feb 2010 19:25:01 +0530
changeset 36 a542eb905ced
parent 34 18b34db550ec
child 38 194e1bdfd1cb
permissions -rw-r--r--
Testing

#!/usr/bin/python
"""
Just a hack to convert rst to xml and then docbook . 
May not containt all the required elements of a docbook .
Just done to make it run for the specific rst for our 
sees documentation.
"""
import xml.etree.ElementTree as ET
import os 
import re
import subprocess
import os
import pkg_resources
import time
from docutils.core import publish_file 
import os
chapterno=0
tmp_folder="/home/hg/repos/SEES-hacks/temp/"








def convert2xml(file_name):
    """ convert to xml using rst2xml internally """
    global chapterno    
    file_name=file_name.split()[0]
    name=file_name.split('/')[-1]
   
    xml_file_temp='/'.join(file_name.split('/')[:-2])
     
    name='ch'+str(chapterno)+name.split('.')[0]
    xml_file=tmp_folder+name+'.xml'
    print xml_file   
#    a=open(xml_file,'w')
    publish_file(source_path=file_name, destination_path=xml_file,parser_name='restructuredtext', writer_name='xml') 
    
def walk(repo):
    global chapterno
#    mainfolder='/home/hg/repos/sttp/'    
    for readline in open('/home/hg/repos/SEES-hacks/SEESenv/scripts/index.config','r').readlines():
        chapterno+=1		
        filename=repo+readline
        convert2xml(filename)
       




if __name__=='__main__':
    repo='/home/hg/repos/sttp/'
    walk(repo)
#    convert(1,2,3)