# # This is the master program which processes web pages and directories # for the GouldHome site. # # This program takes 1 parameter. The parameter is the name of a directory # or the name of a file. Specifically, it understands the following cases: # # (1) webPage c:\...\GouldHome\daphne\index.go # This means to process the single index.go file in the daphne # subdirectory. If there is a c:\...\GouldHome\daphne\index # subdirectory containing images then thumbnail pages (both .gon # and .html) will be created as well. # # (2) webProc c:\...\GouldHome\daphne\savoy # This means to create a .gon file (or files) for access to the images # in the savoy subdirectory and then to create corresponding .html files. # However, if there is a savoy.go file then this command has the exact # same effect as webProc c:\...\GouldHome\daphne\savoy.go # # (3) webProc c:\...\GouldHome\daphne # This means to process all the .go and .gon files in the daphne # subdirectory. This command can only be used on the currently # supported directories: # c:\...\GouldHome # c:\...\GouldHome\daphne # c:\...\GouldHome\joel # c:\...\GouldHome\beth # c:\...\GouldHome\ben # c:\...\GouldHome\events # c:\...\GouldHome\orienteering # import os import re import sys import glob import string import traceback import makePage import makeThumb from stat import * gouldHome = makePage.gouldHome sectionNames = makePage.sectionNames MyError = makePage.MyError #--------------------------------------------------------------------------- def run(fileName): if fileName[1] != ':' and fileName[0:2] != '\\\\': raise MyError,'File %s must have include an absolute path'%fileName # remove the trailing slash if present if fileName[-1:] == '\\': fileName = fileName[:-1] # figure out the section name dirList = map(string.lower,string.split(fileName,'\\')) if len(dirList) < 2: raise MyError,'File %s must not be in the root directory'%fileName elif dirList[-1] == gouldHome: section = '' inMainDir = 1 elif dirList[-1] in sectionNames and dirList[-2] == gouldHome: section = dirList[-1] inMainDir = 1 elif dirList[-2] == gouldHome: section = '' inMainDir = 0 elif len(dirList) < 3: raise MyError,'File '+fileName+' must be in GouldHome or one of '+repr(sectionNames) elif dirList[-2] in sectionNames and dirList[-3] == gouldHome: section = dirList[-2] inMainDir = 0 else: raise MyError,'File '+fileName+' must be in GouldHome or one of '+repr(sectionNames) # If this is a file then just process that file mode = os.stat(fileName)[ST_MODE] if not S_ISDIR(mode): if fileName[-3:] != '.go' and fileName[-4:] != '.gon': raise MyError,'File %s must have an extension of .go or .gon' % fileName fullMakePage(fileName) return # If this is a main directory, we process every .go and .gon file in the # directory. For every file we process, we first try to create thumbnail # pages. Since this may result in additional .gon files, we relist # every .go and .gon file before processing the pages. if inMainDir: files = glob.glob(fileName+'\\*.go')+glob.glob(fileName+'\\*.gon') for file in files: tryMakeThumb(file) files = glob.glob(fileName+'\\*.go')+glob.glob(fileName+'\\*.gon') for file in files: makePage.run(file) return # If this is an subdirectory and there is a matching .go file then # just process the matching .go file if os.access(fileName+'.go',0): fullMakePage(fileName+'.go',1) return if os.access(fileName+'.gon',0): fullMakePage(fileName+'.gon',1) return # Otherwise assume this is an image directory. We make thumbnails for it # and then post-process the thumbnails. files = makeThumb.run(fileName) for file in files: makePage.run(file) #--------------------------------------------------------------------------- # This checks to see if a thumbnail page needs to be made. If one does # need to be made, this will create the thumbnail page. # # As an optimization, we do not bother creating the thumbnail page if the # most recent date jpg file is less recent that the date of the thumbnail # .gon file itself. def tryMakeThumb(fileName,bForce=0): lastDot = string.rfind(fileName,'.') if lastDot > 0 : fileName = fileName[:lastDot] try: mode = os.stat(fileName)[ST_MODE] if not S_ISDIR(mode): return [] except OSError: return [] if not bForce: try: goTime = os.stat(fileName+'_thumb.gon')[ST_MTIME] files = glob.glob(fileName+'\\*.jpg') for file in files: jpgTime = os.stat(fileName)[ST_MTIME] if jpgTime > goTime: break else: return [] except OSError: pass return makeThumb.run(fileName) #--------------------------------------------------------------------------- # This first makes any necessary thumbnail pages, then it process the .go # page and any .gon pages created as a side effect of making the thumbnails def fullMakePage(fileName,bForce=0): files = tryMakeThumb(fileName,bForce) makePage.run(fileName) for file in files: makePage.run(file) #--------------------------------------------------------------------------- if __name__=='__main__': try: if len(sys.argv) != 2: print 'Run this program by typing the following command at a DOS prompt:' print ' makePage.py ' print 'or' print ' makePage.py ' else: run(sys.argv[1]) except MyError: print 'Error:' print sys.exc_value except: traceback.print_exc() raw_input('Press Enter to exit')