/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: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
 
1
#!/usr/bin/python3
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
 
29
31
import os
30
32
import re
31
33
import shutil
35
37
 
36
38
verbose = False
37
39
 
38
 
IMAGE_DIRECTIVE_PATTERN = re.compile(ur'^..\s+image::\s+(.*)\s+$')
39
 
DIRECTIVE_ELEMENT_PATTERN = re.compile(ur'^\s+:[^:]+:\s+')
 
40
IMAGE_DIRECTIVE_PATTERN = re.compile(u'^..\\s+image::\\s+(.*)\\`\\s+$')
 
41
DIRECTIVE_ELEMENT_PATTERN = re.compile(u'^\\s+:[^:]+:\\s+')
40
42
 
41
43
class Converter(object):
42
44
    def __init__(self, srcdir, destdir):
72
74
            if directive_match is not None:
73
75
                image_src = directive_match.group(1)
74
76
                if verbose:
75
 
                    print('Image ' + image_src + ' in ' + filename
76
 
                          + ': ' + line.strip())
 
77
                    print(('Image ' + image_src + ' in ' + filename
 
78
                          + ': ' + line.strip()))
77
79
 
78
80
                foundimg = True
79
81
            outfile.write(line)
94
96
    def replace_extension(self, path, newext):
95
97
        if path.endswith(newext):
96
98
            raise Exception("File '" + path + "' already has extension '"
97
 
                            + newext +"'")
 
99
                            + newext + "'")
98
100
        dot = path.rfind('.')
99
101
        if dot == -1:
100
102
            return path + newext
142
144
    destdir = None
143
145
 
144
146
    if len(argv) < 2:
145
 
        print('Usage: ' + argv[0] + ' ' + IN_DIR_OPT + 'INDIR '
146
 
              + OUT_DIR_OPT + 'OUTDIR')
147
 
        print
 
147
        print(('Usage: ' + argv[0] + ' ' + IN_DIR_OPT + 'INDIR '
 
148
              + OUT_DIR_OPT + 'OUTDIR'))
 
149
        print()
148
150
        print('This will convert all .txt files in INDIR into file in OUTDIR')
149
151
        print('while adjusting the use of images and possibly converting SVG')
150
152
        print('images to PDF files so LaTeX can include them.')
158
160
        elif arg.startswith(OUT_DIR_OPT):
159
161
            destdir = arg[len(OUT_DIR_OPT):]
160
162
        else:
161
 
            print('Invalid argument ' + arg)
 
163
            print(('Invalid argument ' + arg))
162
164
            sys.exit(1)
163
165
 
164
166
    if srcdir is None or destdir is None:
165
 
        print('Please specify the ' + IN_DIR_OPT + ' and '
166
 
              + OUT_DIR_OPT + ' options.')
 
167
        print(('Please specify the ' + IN_DIR_OPT + ' and '
 
168
              + OUT_DIR_OPT + ' options.'))
167
169
        sys.exit(1)
168
170
 
169
171
    if not os.path.exists(destdir):