texi2html in a cgi ?

  • Thread starter =?ISO-8859-1?Q?=D8ystein_Johansen?=
  • Start date
?

=?ISO-8859-1?Q?=D8ystein_Johansen?=

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.)
 
M

Miki Tebeka

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 :)
 
?

=?ISO-8859-1?Q?=D8ystein_Johansen?=

Miki said:
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!
The more you'll know the deeper you'll fall in love :)

More and more each day!

Thanks,
-Øystein
 
?

=?ISO-8859-1?Q?=D8ystein_Johansen?=

Miki said:
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!
The more you'll know the deeper you'll fall in love :)

More and more each day!

Thanks,
-Øystein
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top