texi2html in a cgi ?

Øystein Johansen oystein at gnubg.org
Wed Sep 17 22:15:23 CEST 2003


Miki Tebeka wrote:
> 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)

It works locally with the file below:

#!/usr/bin/python
from texi2html import TexinfoParser, HTMLHelp
from tempfile import gettempdir
from os.path import dirname, join
 

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

to_html("faq.texi")

It creates several html files in /tmp/, one file for each section, but 
how do I create only one file, faq.html?

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

I will!

>>(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 and more each day!

Thanks,
-Øystein





More information about the Python-list mailing list