473,385 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

texi2html in a cgi ?

Hi,

I'm trying to build a new web site for the GNU Backgammon project, and I
want a cgi program to fetch the file faq.texi from the projects cvs and
then display it on web page formatted with html.

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?

Regards,
-Øystein

(Unexperienced Python programmer, who has just fallen in love with this
beautiful programming language.)

Jul 18 '05 #1
3 1516
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 :-)
Jul 18 '05 #2
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

Jul 18 '05 #3
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

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.