#---------------------------------------------------------------------- # poohelp2html.py JJS 4/13/97 # # This module converts POO help files into HTML. It is a stand- # alone utility, not used or needed by the POO engine. # #---------------------------------------------------------------------- import poohelp import os from time import * import string gTopic = '' def header(title): out = "" + title + '\n' \ "

" + title + '\n' \ "

" return out def footer(surpressLink = 0): out = '' if not surpressLink: out = '

[Top]
' out = out + "


" + ctime(time()) + "\n" return out def word(w): w = string.lstrip(w) if not w: return '' prestuff = '' while w and w[0] in "(),.!?;:": prestuff = prestuff + w[0] w = w[1:] poststuff = '' while w and w[-1] in "(),.!?;:": poststuff = w[-1] + poststuff w = w[:-1] if w != gTopic and w in poohelp.helpDB.keys(): return prestuff + '' + w + '' + poststuff return prestuff + w + poststuff def makesafe(str): out = string.join(string.split(str,'<'),'<') out = string.join(string.split(out,'>'),'>') return out def body(str): lines = string.split(str,'\n') out = '' intable = 0 for l in lines: l = makesafe(l) if l[:3] == ' ': if not intable: out = out + '
\n' intable = 1 out = out + '' for w in filter( lambda x:x, string.split(l," ")): out = out + '' out = out + '\n' else: if intable: out = out + '
' + word(w) + '
' intable = 0 if l == '': out = out + '

' elif l[:7] == "Syntax:": out = out + 'Syntax: ' + \ l[8:] + '

' else: out = out + string.join( map(lambda w:word(w), string.split(l) )) out = out + '\n' return out #--------------------------------------------------------------- # load database print "Loading database..." poohelp.hLoad() print "Creating html files..." # change directory #os.mkdir('poohelp') os.chdir('poohelp') # create the main file print "index.html..." f = open('index.html', 'w') f.write(header('POO Help')) f.write(body( poohelp.help()) ) f.write(footer(1)) # create particular topic files for gTopic in poohelp.helpDB.keys(): filename = gTopic + ".html" print filename+"..." f = open(filename, 'w') f.write(header(gTopic)) f.write(body( poohelp.help(gTopic) )) f.write(footer()) print "All done!"