[Python-checkins] r50662 - sandbox/trunk/seealso/convert-python-faqs.py

andrew.kuchling python-checkins at python.org
Sat Jul 15 04:16:56 CEST 2006


Author: andrew.kuchling
Date: Sat Jul 15 04:16:55 2006
New Revision: 50662

Modified:
   sandbox/trunk/seealso/convert-python-faqs.py
Log:
Write indexes

Modified: sandbox/trunk/seealso/convert-python-faqs.py
==============================================================================
--- sandbox/trunk/seealso/convert-python-faqs.py	(original)
+++ sandbox/trunk/seealso/convert-python-faqs.py	Sat Jul 15 04:16:55 2006
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/Users/amk/source/p/python/python.exe
 # Read copy of the pyfaq infogami site (assumed to be in the pyfaq/
 # subdirectory) and write out a pyramid-formatting tree to pyramid-faq/
 #
@@ -48,7 +48,8 @@
         s = ET.tostring(child, 'utf-8')
         f.write(s)
 
-    # XXX should add a link to the wiki page for this question
+    # Add a link to the wiki page for this question
+    f.write('''<p><a href="http://pyfaq.infogami.com/%s">[Edit/comment on this page]</a></p>\n''' % base)
     f.close()
 
     # Write .yml files
@@ -73,12 +74,54 @@
     breadcrumb: !breadcrumb nav.yml nav
     text: !htmlfile question.html""")
     f.close()
-
              
     
 def convert_index (filename):
     root = htmlload.load(filename)
+    title = root.findtext('*/title')
+    i = title.find(':')
+    category = title[i+1:].strip()
+
+    # XXX can there be subsections within a category?
+    entries = []
+    for para in root.findall('*/p'):
+	a = para.find('a')
+	if a is not None:
+  	    entries.append(a)
+
+    idir = os.path.join(DESTDIR, category)
+
+    # Write body of question
+    f = open(os.path.join(idir, 'listing.html'), 'w')
+    f.write('<ul>\n')
+    for a in entries:
+        f.write('<li>%s</li>\n' % ET.tostring(a, 'utf-8'))
+    f.write('</ul>\n')
+    f.close()
+	
+    # Write .yml files
+    f = open(os.path.join(idir, 'index.yml'), 'w')
+    f.write("""--- !fragment
+template: index.html
+# The data to pass to the template
+local:
+  title: %s
+  content: !fragment content.yml
+    """ % title)
+    f.close()
+
+    f = open(os.path.join(idir, 'content.yml'), 'w')
+    f.write("""--- !fragment
+# Type of template to use
+template: content.html
 
+# The data to pass to the template
+local:
+  content:
+    breadcrumb: !breadcrumb nav.yml nav
+    text: !htmlfile listing.html""")
+    f.close()
+    
 def write_master_index (index_files):
     pass
 


More information about the Python-checkins mailing list