home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / diveintopython / examples / builddialectexamples.py < prev    next >
Encoding:
Python Source  |  2004-05-05  |  1.1 KB  |  33 lines

  1. """Build examples of output of dialect module
  2.  
  3. This script is used during the build process of "Dive Into Python"
  4. (http://diveintopython.org/) to create examples of the output of the
  5. code in chapter 4 (dialect.py and BaseHTMLProcessor.py).
  6.  
  7. It takes one argument, the source HTML file to translate.  It outputs
  8. chef.html, fudd.html, and olde.html in the same directory as the source.
  9.  
  10. Safe to run more than once.  Output files are silently overridden if
  11. they already exist.
  12. """
  13.  
  14. __author__ = "Mark Pilgrim (mark@diveintopython.org)"
  15. __version__ = "$Revision: 1.2 $"
  16. __date__ = "$Date: 2004/05/05 21:57:19 $"
  17. __copyright__ = "Copyright (c) 2001 Mark Pilgrim"
  18. __license__ = "Python"
  19.  
  20. import dialect
  21. import sys, os
  22.  
  23. def translateAndWrite(filename, dialectname):
  24.     targetfilename = os.path.join(os.path.split(filename)[0], "%s.html" % dialectname)
  25.     fsock = open(targetfilename, "wb")
  26.     fsock.write(dialect.translate(filename, dialectname))
  27.     fsock.close()
  28.  
  29. if __name__ == "__main__":
  30.     filename = sys.argv[1]
  31.     for dialectname in ("chef", "fudd", "olde"):
  32.         translateAndWrite(filename, dialectname)
  33.