PyXR

C:\Python24\Lib\site-packages\pyxr \ buildWeb.py



0001 # Copyright 2003, Grant T. Olson, see License.txt for details
0002 
0003 import misc,astToHtml, os, sys
0004 from pageText import pageText
0005 import traceback
0006 from parser import ParserError
0007 
0008 def ensureDirectory(directory):
0009     try:
0010         dirs = os.makedirs(directory)
0011     except OSError:
0012         pass # dir already exists
0013 
0014 def rootPageGen():
0015     if misc.verbose:
0016         print "Generating root index page"
0017     else:
0018         sys.stdout.write(".");sys.stdout.flush();
0019     dirname = misc.cacheLocation
0020     ensureDirectory(dirname)
0021     output = file (os.path.join(dirname, misc.indexPage), "w")
0022     pt = pageText(misc.virtualLocation, write=output.write)
0023     pt.writeRootText()
0024     output.close()
0025 def dirPageGen(directory):
0026     if misc.verbose:
0027         print "Generating directory page %s " % directory
0028     else:
0029         sys.stdout.write('.');sys.stdout.flush();
0030     dirname = "%s%s" % (misc.cacheLocation,
0031                         os.path.normcase(misc.pathToFileName(directory)))
0032     ensureDirectory(dirname)
0033     filename = os.path.join(dirname, misc.indexPage)
0034     output = file(filename, "w")
0035     pt = pageText(misc.virtualLocation,write=output.write)
0036     pt.writePackageText(directory)
0037     output.close()
0038     
0039 def pageCache(fil):
0040     if misc.verbose:
0041         print "Generating page for %s" % fil
0042     else:
0043         sys.stdout.write(".");sys.stdout.flush();
0044     filename = "%s%s.html" % (misc.cacheLocation, misc.pathToFileName(fil))
0045     output = file(filename, "w")
0046     #x = astToHtml.astToHtml(fil, output.write)
0047     #x.process()
0048     pt = pageText(misc.virtualLocation, write=output.write)
0049     pt.writeFileText(fil,)
0050     output.close()
0051 
0052 def cacheAll():
0053     print "Generating Static pages (10-20 minutes, grab a beer if you haven't already)...",
0054     print
0055 
0056     rootPageGen()
0057     for directory in misc.sourceDirList():
0058         try:
0059             dirPageGen(directory)
0060         except KeyboardInterrupt:
0061             raise
0062         except:
0063             if sys.exc_info()[0] not in (ParserError, SyntaxError):
0064                 raise
0065             msg = "Failed Processing Directory %s" % directory
0066             if misc.skipInvalidFiles:
0067                 print msg
0068             else:
0069                 raise RuntimeError, msg , sys.exc_traceback
0070     for fil in misc.sourceFileList():
0071         try:
0072             pageCache(fil)
0073         except KeyboardInterrupt:
0074             raise
0075         except:
0076             if sys.exc_info()[0] not in (ParserError, SyntaxError):
0077                 raise
0078             msg = "\nUnable to process file %s:\nInvalid Python Source Code\n" % fil
0079             if misc.skipInvalidFiles:
0080                 print msg
0081             else:
0082                 raise RuntimeError(msg + "\nSet skipInvalidFiles=1 in settings.cfg to continue on error\n")
0083             
0084 if __name__ == "__main__":
0085     import nsNode
0086     if len(sys.argv) == 1:
0087         import nsNode
0088         nsNode.loadTree()
0089     elif len(sys.argv) == 2:
0090         print "loading index(a minute or two)"
0091         import nsNode
0092         nsNode.loadTreeFromFile(sys.argv[1])
0093     else:
0094         print "Invalid syntax"
0095         sys.exit()
0096     nsNode.nsNode.baseHREF = misc.virtualLocation
0097     cacheAll()
0098 
0099 

Generated by PyXR 0.9.4
SourceForge.net Logo