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.) 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 :-)
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. |