# Figure out which other elements of an episode page are available. import os, string # Check for the existence of a file. def exists(filename): try: os.stat(filename) return 1 except: return 0 # # Input: integer episode number # Output: (guide, background, synopsis, credits, prev, next) # def getneighbors(which, page = 'guide'): whichstr = '%03d' % which prev = '%03d' % (which - 1) next = '%03d' % (which + 1) hasg = exists('../guide/' + whichstr + '.html') hasb = exists('../background/' + whichstr + '.shtml') hass = exists('../synops/' + whichstr + '.html') hasc = exists('../credits/' + whichstr + '.html') if exists(prev + '.html') or exists(prev + '.shtml'): hasp = 1 else: hasp = 0 if exists(next + '.html') or exists(next + '.shtml'): hasn = 1 else: hasn = 0 if page == 'comic' or page == 'novels': hasb = 0 hass = 0 hasc = 0 return (hasg, hasb, hass, hasc, hasp, hasn) # # Generate a trio of navigational buttons for headers and footers. # def navbuttons(num, align = 'middle', which = 'guide'): (hasg, hasb, hass, hasc, hasp, hasn) = getneighbors(num, which) if which == 'background': extension = '.shtml' else: extension = '.html' curep = num cureplong = '%03d' % (curep) prevep = '%03d' % (curep - 1) nextep = '%03d' % (curep + 1) if which == 'comic' or which == 'novels': output = """[Index] """ else: output = """[Episode List] """ if hasp: output=output+ """[Previous] """ else: output = output + """""" if hasn: output=output+ """[Next] """ else: output = output + """""" return output # # Devise a page header based on the current episode number and which page # we're making. # def pageheader(num, page, do_jpeg = 0): (hasg, hasb, hass, hasc, hasp, hasn) = getneighbors(num, page) curep = num cureplong = '%03d' % (curep) prevep = '%03d' % (curep - 1) nextep = '%03d' % (curep + 1) if page == 'comic': titleprefix = 'c' titlewidth = 422 picname = 'comic/' + cureplong elif page == 'novels': titleprefix = 'n' titlewidth = 427 picname = 'novels/' + cureplong else: titleprefix = 'e' titlewidth = 340 pix = open('../internal/picnames', 'r') for i in range(0, curep + 1): picname = pix.readline()[:-1] pix.close() if picname == '': picname = 'XXX' if picname == 'none': picname = 'tv-blank' else: picname = cureplong + '/' + picname curep = `curep` picwidth = 500 - titlewidth output = """

[Home]
""" if page == 'comic' or page == 'novels': output = output + '' if do_jpeg and picname != 'tv-blank': extension = '.jpeg' else: extension = '.gif' output = output + """' if page == 'comic' or page == 'novels': output = output + '' output = output + """
""" if page == 'guide' or page == 'novels' or page == 'comic': output = output + """ ### GUIDE ### """ else: if hasg: output = output + """[Guide] """ else: output = output + """""" if page == 'background': output = output + """ ### BACKGROUND ### """ else: if hasb: output=output+ """[Background] """ else: output = output + """""" if page == 'synopsis': output = output + """ ### SYNOPSIS ### """ else: if hass: output=output + """[Synopsis] """ else: output = output + """""" if page == 'credits': output = output + """ ### CREDITS ### """ else: if hasc: output=output+ """[Credits] """ else: output = output + """""" output = output + navbuttons(num, 'middle', page) + "\n
\n" return output def pagefooter(num, page = 'guide'): output = """

[Home] [Top] [Comments] """ output = output + navbuttons(num, 'bottom', page) + '\n\n' return output # # Given an image path, generate the full path to the corresponding file. # def normalize_path(path): if path[0:4] == '/lurk/': path = '/home/koreth/lurk' + path[5:] elif path[0] == '/': path = '/home/midwinter/docroot' + path return path # # Check all the images in a document and substitute JPEGs for GIFs where # JPEGs exist. # def mungeimages(text, do_jpeg): # # GIF is what's in the source, so do nothing if that's the output # if do_jpeg == 0: return text result = '' for chunk in string.splitfields(text, '.gif'): filepos = string.rfind(chunk, '"') if filepos < 0: result = result + chunk break path = normalize_path(chunk[filepos + 1:]) if exists(path + '.jpeg'): extension = '.jpeg' elif exists(path + '.gif'): extension = '.gif' else: extension = '' result = result + chunk + extension return result