texi2html in a cgi ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Øystein Johansen

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

  • Miki Tebeka

    #2
    Re: texi2html in a cgi ?

    Hello Øystein,
    [color=blue]
    > 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?[/color]
    I see two ways:
    1. Write the texi file to disk (use tempfile.mkstem p) 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.sethtmlh elp(HTMLHelp("" ,""))
    parser.setinclu dedir(dirname(f ile))
    parser.setdirna me(outdir)
    parser.parse(op en(file))
    return join(outdir, "%s.html" % parser.topname)

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

    HTH.
    Miki.

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

    Comment

    • Øystein Johansen

      #3
      Re: texi2html in a cgi ?

      Miki Tebeka wrote:[color=blue]
      > I see two ways:
      > 1. Write the texi file to disk (use tempfile.mkstem p) 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.sethtmlh elp(HTMLHelp("" ,""))
      > parser.setinclu dedir(dirname(f ile))
      > parser.setdirna me(outdir)
      > parser.parse(op en(file))
      > return join(outdir, "%s.html" % parser.topname)[/color]

      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.sethtmlh elp(HTMLHelp("" ,""))
      parser.setinclu dedir(dirname(f ile))
      parser.setdirna me(outdir)
      parser.parse(op en(file,"r"))
      return join(outdir, "%s.html" % parser.topname)


      to_html("faq.te xi")

      It creates several html files in /tmp/, one file for each section, but
      how do I create only one file, faq.html?
      [color=blue]
      > Remeber to delete the directory from time to time ...[/color]

      I will!
      [color=blue][color=green]
      >>(Unexperience d Python programmer, who has just fallen in love with this
      >>beautiful programming language.)[/color]
      >
      > The more you'll know the deeper you'll fall in love :-)[/color]

      More and more each day!

      Thanks,
      -Øystein

      Comment

      • Øystein Johansen

        #4
        Re: texi2html in a cgi ?

        Miki Tebeka wrote:[color=blue]
        > I see two ways:
        > 1. Write the texi file to disk (use tempfile.mkstem p) 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.sethtmlh elp(HTMLHelp("" ,""))
        > parser.setinclu dedir(dirname(f ile))
        > parser.setdirna me(outdir)
        > parser.parse(op en(file))
        > return join(outdir, "%s.html" % parser.topname)[/color]

        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.sethtmlh elp(HTMLHelp("" ,""))
        parser.setinclu dedir(dirname(f ile))
        parser.setdirna me(outdir)
        parser.parse(op en(file,"r"))
        return join(outdir, "%s.html" % parser.topname)


        to_html("faq.te xi")

        It creates several html files in /tmp/, one file for each section, but
        how do I create only one file, faq.html?
        [color=blue]
        > Remeber to delete the directory from time to time ...[/color]

        I will!
        [color=blue][color=green]
        >>(Unexperience d Python programmer, who has just fallen in love with this
        >>beautiful programming language.)[/color]
        >
        > The more you'll know the deeper you'll fall in love :-)[/color]

        More and more each day!

        Thanks,
        -Øystein

        Comment

        Working...