SEESenv/scripts/myrst2xml.py
author amit@thunder
Fri, 12 Feb 2010 01:11:21 +0530
changeset 2 52d12eb31c30
parent 0 scripts/myrst2xml.py@8083d21c0020
child 27 cb14131583c6
permissions -rw-r--r--
Virtual enviroment for SEES-hacks added ...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     1
#!/usr/bin/python
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     2
"""
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     3
Just a hack to convert rst to xml and then docbook . 
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     4
May not containt all the required elements of a docbook .
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     5
Just done to make it run for the specific rst for our 
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     6
sees documentation.
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     7
"""
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     8
import xml.etree.ElementTree as ET
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
     9
import os 
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    10
import re
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    11
import subprocess
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    12
import os
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    13
import pkg_resources
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    14
import time
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    15
from docutils.core import publish_file 
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    16
chapterno=0
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    17
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    18
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    19
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    20
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    21
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    22
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    23
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    24
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    25
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    26
def convert2xml(file):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    27
#    print folder,subfolder,file
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    28
    file=file.split("\n")[0]
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    29
    file= file.split("\t")[0]  
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    30
    global chapterno
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    31
    name=file.split('/')[-1]
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    32
    name='ch'+str(chapterno)+name.split('.')[0]
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    33
#    full_file=os.path.join(folder,file)    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    34
#    if file.endswith('.rst'):    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    35
    print file	    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    36
    xml_file=name+'.xml'        
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    37
    a=open(xml_file,'w')
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    38
#    a.close()
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    39
#    command="rst2xml.py %s > %s" %(file , xml_file)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    40
          
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    41
#    a=subprocess.Popen(command , shell=True)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    42
#    time.sleep(10) 	   	
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    43
#    a.kill()
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    44
    publish_file(source_path=file, destination_path=xml_file,parser_name='restructuredtext', writer_name='xml') 
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    45
def walk(repo):
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    46
    global chapterno
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    47
    mainfolder='/home/amit/sttp_latest/'    
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    48
    for readline in open('index.config','r').readlines():
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    49
        chapterno+=1		
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    50
        filename=mainfolder+readline
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    51
        convert2xml(filename)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    52
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    53
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    54
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    55
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    56
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    57
if __name__=='__main__':
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    58
    repo='/home/amit/sphinxvirt/review/'
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    59
    walk(repo)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    60
#    convert(1,2,3)
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    61
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    62
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    63
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    64
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    65
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    66
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    67
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    68
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    69
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    70
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    71
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    72
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    73
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    74
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    75
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    76
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    77
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    78
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    79
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    80
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    81
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    82
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    83
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    84
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    85
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    86
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    87
8083d21c0020 The first commit of all the required files for the review app
amit@thunder
parents:
diff changeset
    88