author | amit@thunder |
Sun, 21 Feb 2010 23:32:34 +0530 | |
changeset 11 | a7bd4bca6f6e |
parent 6 | 1ce9b33fb6ff |
child 26 | 1846ab4ebdda |
permissions | -rw-r--r-- |
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 glob, os, re, sys |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
15 |
names = glob.glob('ch*.xml') |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
16 |
""" |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
17 |
chapterno=0 |
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 |
def convert2xml(file): |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
20 |
# print folder,subfolder,file |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
21 |
global chapterno |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
22 |
name=file.split('/')[-1] |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
23 |
name=str(chapterno)+name.split('.')[0] |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
24 |
# 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
|
25 |
# if file.endswith('.rst'): |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
26 |
print file |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
27 |
xml_file=name+'.xml' |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
28 |
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
|
29 |
print command |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
30 |
a=subprocess.Popen(command , shell=True) |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
31 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
32 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
33 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
34 |
def walk(repo): |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
35 |
global chapterno |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
36 |
mainfolder='/home/amit/sttp_latest/' |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
37 |
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
|
38 |
chapterno+=1 |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
39 |
filename=mainfolder+readline |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
40 |
convert2xml(filename) |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
41 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
42 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
43 |
""" |
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
44 |
def convert2docbook(xml_string): |
6 | 45 |
""" convert to docbook from xml converted using rst2xml using regex replacements """ |
4 | 46 |
xml_string=re.sub('<strong>','<emphasis role="strong">', xml_string) |
47 |
xml_string=re.sub('<literal_block xml:space="preserve">','<programlisting>',xml_string) |
|
48 |
xml_string=re.sub('</literal_block>','</programlisting>',xml_string) |
|
49 |
xml_string=re.sub('<paragraph>' ,'<para>',xml_string) |
|
50 |
xml_string=re.sub('</paragraph>' ,'</para>',xml_string) |
|
51 |
xml_string=re.sub('</strong>' ,'</emphasis>',xml_string) |
|
52 |
xml_string=re.sub('<bullet_list bullet="[-*+]">','<itemizedlist mark="*">',xml_string,) |
|
53 |
xml_string=re.sub('</bullet_list>','</itemizedlist>',xml_string) |
|
54 |
xml_string=re.sub('<list_item>','<listitem>',xml_string) |
|
55 |
xml_string=re.sub('</list_item>','</listitem>',xml_string) |
|
56 |
xml_string=re.sub('<enumerated_list enumtype="arabic" prefix="" suffix=".">', '<orderedlist numeration="arabic">',xml_string) |
|
57 |
xml_string=re.sub('</enumerated_list>', '</orderedlist>',xml_string) |
|
6 | 58 |
xml_string=re.sub('<block_quote>', '',xml_string) |
59 |
xml_string=re.sub('</block_quote>', '',xml_string) |
|
60 |
xml_string=re.sub('<definition_list>', '',xml_string) |
|
61 |
xml_string=re.sub('</definition_list>', '',xml_string) |
|
4 | 62 |
xml_string=re.sub('<entry>', '',xml_string) |
63 |
xml_string=re.sub('</entry>', '',xml_string) |
|
64 |
xml_string=re.sub('<row>', '',xml_string) |
|
65 |
xml_string=re.sub('</row>', '',xml_string) |
|
66 |
xml_string=re.sub('<tbody>', '',xml_string) |
|
67 |
xml_string=re.sub('</tbody>', '',xml_string) |
|
68 |
xml_string=re.sub('<table>', '',xml_string) |
|
69 |
xml_string=re.sub('</table>', '',xml_string) |
|
70 |
xml_string=re.sub('<thead>', '',xml_string) |
|
71 |
xml_string=re.sub('</thead>', '',xml_string) |
|
72 |
# xml_string=re.sub('<tgroup cols="[1-90]*"><colspec colwidth="[1-90]*"/><colspec colwidth="[1-90]*"/><colspec colwidth="[1-90]"/>', '',xml_string) |
|
73 |
# xml_string=re.sub('</tgroup', '',xml_string) |
|
74 |
chapter= ET.Element("chapter") |
|
75 |
article=ET.SubElement(chapter,"article") |
|
76 |
articleinfo=ET.SubElement(article,"articleinfo") |
|
77 |
||
78 |
try: |
|
79 |
tree = ET.fromstring(xml_string) |
|
80 |
except: |
|
81 |
print "xml_string problem" |
|
82 |
# print "fromstring" |
|
83 |
try: |
|
84 |
title= ET.SubElement(articleinfo,"title") |
|
85 |
title.text=tree.items()[1][1] |
|
86 |
except: |
|
87 |
pass |
|
88 |
article.insert(1,tree) |
|
89 |
xml_string=ET.tostring(chapter) |
|
90 |
xml_string=re.sub('<document [A-Za-z=/_."]*>' ,'',xml_string) |
|
91 |
xml_string=re.sub('</document>' ,'',xml_string) |
|
92 |
return xml_string |
|
93 |
||
94 |
||
0
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
95 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
96 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
97 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
98 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
99 |
if __name__=='__main__': |
4 | 100 |
for name in names: |
101 |
#print name |
|
5 | 102 |
xml_string=open(name,'r').read() |
103 |
#xml_string=open('ch9Using_Linux_Tools.xml','r').read() |
|
4 | 104 |
xml_string=convert2docbook(xml_string) |
105 |
docbook_file=name.split('.')[0]+'.docbook' |
|
106 |
f=open(docbook_file,'w') |
|
107 |
try: |
|
108 |
f.write(xml_string) |
|
109 |
except: |
|
110 |
pass |
|
0
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
111 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
112 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
113 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
114 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
115 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
116 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
117 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
118 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
119 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
120 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
121 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
122 |
|
8083d21c0020
The first commit of all the required files for the review app
amit@thunder
parents:
diff
changeset
|
123 |