[Commits] python.it commit r216 - www/trunk/scripts/ht2html

commit a svn.python.it commit a svn.python.it
Ven 15 Set 2006 13:06:53 CEST


Author: manlio
Date: Fri Sep 15 13:06:48 2006
New Revision: 216

Added:
   www/trunk/scripts/ht2html/linksvalidate.py   (contents, props changed)
Log:
aggiunto validatore per file links

Added: www/trunk/scripts/ht2html/linksvalidate.py
==============================================================================
--- (empty file)
+++ www/trunk/scripts/ht2html/linksvalidate.py	Fri Sep 15 13:06:48 2006
@@ -0,0 +1,66 @@
+"""Validate a links file.
+
+Author: Manlio Perillo
+"""
+
+import sys
+import os
+
+
+
+doctypes = {
+    'strict' : """<!DOCTYPE html 
+    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">""",
+
+    'transitional': """<!DOCTYPE html 
+    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">"""
+}
+
+
+template = """<?xml version="1.0" encoding="ISO-8859-1"?>
+%s
+<html xmlns="http://www.w3.org/1999/xhtml" 
+      xml:lang="it" lang="it">
+   <head>
+      <title>Links</title>
+   </head>
+   <body>
+     <ul>%s</ul>
+   </body>
+</html>
+"""
+
+# XXX TODO use a system catalog
+cmd = "xmllint --noout --valid --loaddtd -"
+
+
+buf = []
+# read and adjust the links file
+for line in file(sys.argv[1]):
+    # list items must be on one single line
+    if line.startswith("<li>"):
+        line = line[:-1] + "</li>\n"
+
+    line = line.replace("h3>", "li>")
+   
+    buf.append(line)
+
+body = ''.join(buf)
+
+# XXX TODO from command line
+doctype = doctypes['strict']
+
+doc = template % (doctype, body)
+
+fpin, fpout = os.popen4(cmd)
+fpin.write(doc)
+fpin.close()
+
+
+ret = fpout.close()
+if ret is not None:
+    print "Document not valid"
+
+sys.exit(ret or 0) # XXX


Maggiori informazioni sulla lista Commits