~dustin-spy/twisted/dustin

« back to all changes in this revision

Viewing changes to twisted/scripts/html2latex.py

  • Committer: moshez
  • Date: 2002-10-25 07:41:23 UTC
  • Revision ID: vcs-imports@canonical.com-20021025074123-4fbcb37163e9d169
Twisted.Lore, the Twisted Document generation lanaguage

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Twisted, the Framework of Your Internet
 
2
# Copyright (C) 2001-2002 Matthew W. Lefkowitz
 
3
 
4
# This library is free software; you can redistribute it and/or
 
5
# modify it under the terms of version 2.1 of the GNU Lesser General Public
 
6
# License as published by the Free Software Foundation.
 
7
 
8
# This library is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
# Lesser General Public License for more details.
 
12
 
13
# You should have received a copy of the GNU Lesser General Public
 
14
# License along with this library; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
17
 
 
18
import os
 
19
from twisted.lore import latex
 
20
from twisted.python import usage
 
21
 
 
22
class Options(usage.Options):
 
23
 
 
24
    optFlags = [['section', 's', 'Generate a section, not an article']]
 
25
 
 
26
    optParameters = [['dir', 'd', None, 'Directory relative to which references'
 
27
                                        ' will be taken']]
 
28
 
 
29
    def parseArgs(self, *files):
 
30
        self['files'] = files
 
31
 
 
32
def run():
 
33
    opt = Options()
 
34
    opt.parseOptions()
 
35
    if opt['section']:
 
36
        klass = latex.SectionLatexSpitter
 
37
    else:
 
38
        klass = latex.LatexSpitter
 
39
    for file in opt['files']:
 
40
        fin = open(file)
 
41
        fout = open(os.path.splitext(file)[0]+'.tex', 'w')
 
42
        dir = opt['dir'] or os.path.dirname(file)
 
43
        spitter = klass(fout.write, dir)
 
44
        spitter.makeConnection(None)
 
45
        spitter.dataReceived(fin.read())
 
46
        fin.close()
 
47
        fout.close()