Some more tags added
authoramit@thunder
Sat, 13 Feb 2010 13:30:22 +0530
changeset 4 231572ecfb59
parent 3 6cee07c589cb
child 5 c9c9819cd5e5
Some more tags added
SEESenv/scripts/rst2docbook.py
--- a/SEESenv/scripts/rst2docbook.py	Sat Feb 13 12:29:22 2010 +0530
+++ b/SEESenv/scripts/rst2docbook.py	Sat Feb 13 13:30:22 2010 +0530
@@ -42,56 +42,68 @@
 
 """
 def convert2docbook(xml_string):
-#    xml_file_obj=open(file,'r')
-#    xml_string=xml_file_obj.read() 
-#    xml_file_obj.close()       
-    try:
-        xml_string=re.sub('<strong>','<emphasis role="strong">', xml_string)   
-        xml_string=re.sub('<literal_block','<programlisting>',xml_string)
-        xml_string=re.sub('</literal_block>','</programlisting>',xml_string)
-        xml_string=re.sub('xml:space="preserve">','',xml_string)
-        xml_string=re.sub('<paragraph>' ,'<para>',xml_string)
-        xml_string=re.sub('</paragraph>' ,'</para>',xml_string)  
-        xml_string=re.sub('</strong>' ,'</emphasis>',xml_string)
-        chapter= ET.Element("chapter")
-        article=ET.SubElement(chapter,"article")
-        articleinfo=ET.SubElement(article,"articleinfo")
-        tree = ET.fromstring(xml_string)
-        title= ET.SubElement(articleinfo,"title")   
-        try:    
-            title.text=tree.items()[1][1]
-        except:
-                pass    
-        article.insert(1,tree)
-        xml_string=ET.tostring(chapter)
-        xml_string=re.sub('<document ids=.*">' ,'',xml_string)
-        xml_string=re.sub('</document>' ,'',xml_string)
-        return xml_string
-#    docbook_file=file.split('.')[0]+'.docbook'
-#    f=open(docbook_file,'w')
-#    f.write(xml_string)
-#    xml_string=None
-    except :
-        pass
+		
+	xml_string=re.sub('<strong>','<emphasis role="strong">', xml_string)   
+	xml_string=re.sub('<literal_block xml:space="preserve">','<programlisting>',xml_string)
+	xml_string=re.sub('</literal_block>','</programlisting>',xml_string)
+	xml_string=re.sub('<paragraph>' ,'<para>',xml_string)
+	xml_string=re.sub('</paragraph>' ,'</para>',xml_string)  
+	xml_string=re.sub('</strong>' ,'</emphasis>',xml_string)
+	xml_string=re.sub('<bullet_list bullet="[-*+]">','<itemizedlist mark="*">',xml_string,)
+	xml_string=re.sub('</bullet_list>','</itemizedlist>',xml_string)
+	xml_string=re.sub('<list_item>','<listitem>',xml_string)	
+	xml_string=re.sub('</list_item>','</listitem>',xml_string)	
+	xml_string=re.sub('<enumerated_list enumtype="arabic" prefix="" suffix=".">', '<orderedlist numeration="arabic">',xml_string)
+ 	xml_string=re.sub('</enumerated_list>', '</orderedlist>',xml_string)
+	xml_string=re.sub('<entry>', '',xml_string)	
+	xml_string=re.sub('</entry>', '',xml_string) 	
+	xml_string=re.sub('<row>', '',xml_string)	
+	xml_string=re.sub('</row>', '',xml_string)	
+	xml_string=re.sub('<tbody>', '',xml_string)	
+	xml_string=re.sub('</tbody>', '',xml_string)	
+	xml_string=re.sub('<table>', '',xml_string)			
+	xml_string=re.sub('</table>', '',xml_string)	
+	xml_string=re.sub('<thead>', '',xml_string)	
+	xml_string=re.sub('</thead>', '',xml_string)	
+#	xml_string=re.sub('<tgroup cols="[1-90]*"><colspec colwidth="[1-90]*"/><colspec colwidth="[1-90]*"/><colspec colwidth="[1-90]"/>', '',xml_string)
+#	xml_string=re.sub('</tgroup', '',xml_string)	
+	chapter= ET.Element("chapter")
+	article=ET.SubElement(chapter,"article")
+	articleinfo=ET.SubElement(article,"articleinfo")
+		
+	try:	
+		tree = ET.fromstring(xml_string)
+	except:
+		print "xml_string problem"	
+	#	print "fromstring"	
+	try:    
+	        title= ET.SubElement(articleinfo,"title") 
+		title.text=tree.items()[1][1]
+	except:
+	        pass    
+	article.insert(1,tree)
+	xml_string=ET.tostring(chapter)
+	xml_string=re.sub('<document [A-Za-z=/_."]*>' ,'',xml_string)
+	xml_string=re.sub('</document>' ,'',xml_string)
+	return xml_string
+
+    
 
 
 
 
 if __name__=='__main__':
-#    repo='/home/amit/sphinxvirt/review/'
-#    walk(repo)
-#    convert(1,2,3)
-    for name in names:
-        print name        
-        xml_string=open(name,'r').read()
-         
-        xml_string=convert2docbook(xml_string)
-        docbook_file=name.split('.')[0]+'.docbook'
-        f=open(docbook_file,'w')
-        try:        
-            f.write(xml_string)
-        except:
-                pass
+	for name in names:
+		#print name        
+		#xml_string=open(name,'r').read()
+		xml_string=open('ch9Using_Linux_Tools.xml','r').read()
+		xml_string=convert2docbook(xml_string)
+		docbook_file=name.split('.')[0]+'.docbook'
+		f=open(docbook_file,'w')
+		try:        
+		    f.write(xml_string)
+		except:
+		        pass
 
 
 
@@ -105,22 +117,3 @@
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-