texi2html in a cgi ?

Miki Tebeka tebeka at cs.bgu.ac.il
Wed Sep 17 14:07:50 EDT 2003


Hello Øystein,

> I get the file with urllib2. No problem. But how can I parse it and 
> display it? I see there is a file in the Python23/Tools/Scripts/ 
> directory called texi2html.py. How can I use the functions from this 
> file to genrate the webpage?
I see two ways:
1. Write the texi file to disk (use tempfile.mkstemp) and run the script
   (using os.system) on it and send back the result
2. Import texi2html (make sure it's in sys.path) and use it (this is not tested...)
----
from texi2html import TexinfoParser, HTMLHelp
from tempfile import mkdtemp
from os.path import dirname, join

def to_html(file):
    '''Convert texinfo to html. Return top html file'''
    outdir = mkdtemp()
    parser = TexinfoParser()
    parser.sethtmlhelp(HTMLHelp("",""))
    parser.setincludedir(dirname(file))
    parser.setdirname(outdir)
    parser.parse(open(file))
    return join(outdir, "%s.html" % parser.topname)

Remeber to delete the directory from time to time ...

HTH.
Miki.

    
> (Unexperienced Python programmer, who has just fallen in love with this 
> beautiful programming language.)
The more you'll know the deeper you'll fall in love :-)




More information about the Python-list mailing list