/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tools/prepare_for_latex.py

  • Committer: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3
 
1
#!/usr/bin/python
2
2
#
3
3
# Modify reStructuredText 'image' directives by adding a percentage 'width'
4
4
# attribute so that the images are scaled to fit on the page when the document
26
26
# along with this program; if not, write to the Free Software
27
27
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28
28
 
29
 
from __future__ import print_function
30
 
 
31
29
import os
32
30
import re
33
31
import shutil
37
35
 
38
36
verbose = False
39
37
 
40
 
IMAGE_DIRECTIVE_PATTERN = re.compile(u'^..\\s+image::\\s+(.*)\\`\\s+$')
41
 
DIRECTIVE_ELEMENT_PATTERN = re.compile(u'^\\s+:[^:]+:\\s+')
 
38
IMAGE_DIRECTIVE_PATTERN = re.compile(ur'^..\s+image::\s+(.*)\s+$')
 
39
DIRECTIVE_ELEMENT_PATTERN = re.compile(ur'^\s+:[^:]+:\s+')
42
40
 
43
41
class Converter(object):
44
42
    def __init__(self, srcdir, destdir):
74
72
            if directive_match is not None:
75
73
                image_src = directive_match.group(1)
76
74
                if verbose:
77
 
                    print(('Image ' + image_src + ' in ' + filename
78
 
                          + ': ' + line.strip()))
 
75
                    print('Image ' + image_src + ' in ' + filename
 
76
                          + ': ' + line.strip())
79
77
 
80
78
                foundimg = True
81
79
            outfile.write(line)
96
94
    def replace_extension(self, path, newext):
97
95
        if path.endswith(newext):
98
96
            raise Exception("File '" + path + "' already has extension '"
99
 
                            + newext + "'")
 
97
                            + newext +"'")
100
98
        dot = path.rfind('.')
101
99
        if dot == -1:
102
100
            return path + newext
144
142
    destdir = None
145
143
 
146
144
    if len(argv) < 2:
147
 
        print(('Usage: ' + argv[0] + ' ' + IN_DIR_OPT + 'INDIR '
148
 
              + OUT_DIR_OPT + 'OUTDIR'))
149
 
        print()
 
145
        print('Usage: ' + argv[0] + ' ' + IN_DIR_OPT + 'INDIR '
 
146
              + OUT_DIR_OPT + 'OUTDIR')
 
147
        print
150
148
        print('This will convert all .txt files in INDIR into file in OUTDIR')
151
149
        print('while adjusting the use of images and possibly converting SVG')
152
150
        print('images to PDF files so LaTeX can include them.')
160
158
        elif arg.startswith(OUT_DIR_OPT):
161
159
            destdir = arg[len(OUT_DIR_OPT):]
162
160
        else:
163
 
            print(('Invalid argument ' + arg))
 
161
            print('Invalid argument ' + arg)
164
162
            sys.exit(1)
165
163
 
166
164
    if srcdir is None or destdir is None:
167
 
        print(('Please specify the ' + IN_DIR_OPT + ' and '
168
 
              + OUT_DIR_OPT + ' options.'))
 
165
        print('Please specify the ' + IN_DIR_OPT + ' and '
 
166
              + OUT_DIR_OPT + ' options.')
169
167
        sys.exit(1)
170
168
 
171
169
    if not os.path.exists(destdir):