File: Config.py

package info (click to toggle)
plastex 3.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,132 kB
  • sloc: python: 23,341; xml: 18,076; javascript: 7,755; ansic: 46; makefile: 40; sh: 26
file content (391 lines) | stat: -rw-r--r-- 11,491 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
from plasTeX.ConfigManager import *
from typing import Type
from argparse import ArgumentTypeError
import os

def defaultConfig(loadConfigFiles: bool=False):
    config = ConfigManager()

    #
    # General
    #
    general = config.addSection('general')

    general['renderer'] = StringOption(
        """
        Renderer to use for conversion

        This is either one of the built in renderers, or a path to the
        directory of a renderer
        """,
        options = '--renderer',
        default = 'HTML5',
    )

    general['theme'] = StringOption(
        """ Theme for the renderer to use """,
        options = '--theme',
        default = 'default',
    )

    general['extra-templates'] = MultiStringOption(
        """ Extra templates files to use """,
        options='--extra-templates',
        default=[],
    )

    general['copy-theme-extras'] = BooleanOption(
        """  Copy files associated with the theme to the output directory """,
        options = '--copy-theme-extras !--no-theme-extras',
        default = True,
    )

    general['kpsewhich'] = StringOption(
        """ Program which locates LaTeX files and packages """,
        options = '--kpsewhich',
        default = 'kpsewhich',
    )

    general['xml'] = BooleanOption(
        """ Dump XML representation of the document (for debugging) """,
        options = '--xml',
        default = False,
    )

    general['debug'] = BooleanOption(
        """ Parse the document and drop into a debugger.""",
        options = '--debug',
        default = False,
    )

    general['paux-dirs'] = MultiStringOption(
        """Directories where *.paux files should be loaded from.""",
        options = '--paux-dirs',
        default = [],
    )

    general['plugins'] = MultiStringOption(
        """
        A list of plugins to use. Each element must be a valid python module name,
        accessible from the current python path.

        """,
        options = '--plugins',
        default = [],
    )

    general['load-tex-packages'] = BooleanOption(
        """Try to load the TeX implementation of packages having no python
        implementation.""",
        options = '--load-tex-packages !--no-load-tex-packages',
        default = True,
    )

    general['tex-packages'] =  MultiStringOption(
        """
        Packages that we will try to load from their TeX implementation if no
        python implementation is found, even if the load-tex-packages
        option is False.
        """,
        options = '--tex-packages',
        default = [],
    )

    general['packages-dirs'] = MultiStringOption(
        """
        Directories where packages could be implemented in python.
        Use either absolute paths or paths relative to the current directory.
        """,
        options = '--packages-dirs',
        default = [],
    )

    #
    # Links
    #

    links = config.addSection('links')

    class LinksOption(DictOption[str]):
        @classmethod
        def entryFromString(cls, entry: str) -> str:
            return entry

        def registerArgparse(self, group: ArgumentGroup):
            group.add_argument(*self.options, dest=self.name, help=self.description, action='append', nargs='+')

        def updateFromDict(self, data: Dict["str", Any]):
            try:
                data = data[self.name]
                if data is not None:
                    for entry in data:
                        if len(entry) == 2:
                            self.set("{}-title".format(entry[0]), entry[1])
                        elif len(entry) == 3:
                            self.set("{}-url".format(entry[0]), entry[1])
                            self.set("{}-title".format(entry[0]), entry[2])
                        else:
                            raise ArgumentTypeError("--link must be 2 or 3 arguments. {} were supplied".format(len(entry)))
            except KeyError:
                pass

    links['links'] = LinksOption(
        """ Set links for use in navigation """,
        options = '--link',
        default = {},
    )

    #
    # Counters
    #

    counters = config.addSection('counters')

    class CountersOption(DictOption[int]):
        @classmethod
        def entryFromString(cls, entry: str) -> int:
            return int(entry)

        def registerArgparse(self, group: ArgumentGroup):
            group.add_argument(*self.options, dest=self.name, help=self.description, action='append', nargs=2, metavar=("COUNTER", "VALUE"))

    counters['counters'] = CountersOption(
        """ Set initial counter values """,
        options = '--counter',
        default = {}
    )

    files = config.addSection('files', 'File Handling Options')

    files['input-encoding'] = StringOption(
        """ Input file encoding """,
        options = '--input-encoding',
        default = 'utf-8',
    )

    files['output-encoding'] = StringOption(
        """ Output file encoding """,
        options = '--output-encoding',
        default = 'utf-8',
    )

    files['escape-high-chars'] = BooleanOption(
        """ Escape characters that are higher than 7-bit """,
        options = '--escape-high-chars',
        default = False,
    )

    files['split-level'] = IntegerOption(
        """ Highest section level that generates a new file """,
        options = '--split-level',
        default = 2,
    )

    files['log'] = BooleanOption(
        """ Log messages go to log file instead of console """,
        options = '--log',
        default = False,
    )

    files['filename'] = StringOption(
        """ Template for output filenames """,
        options = '--filename',
        default = 'index [$id, sect$num(4)]',
    )

    files['bad-chars'] = StringOption(
        """ Characters that should not be allowed in a filename """,
        options = '--bad-filename-chars',
        default = ': #$%%^&*!~`"\'=?/{}[]()|<>;\\,.', # Double % to escape since we interoplate values
    )

    files['bad-chars-sub'] = StringOption(
        """ Character that should be used instead of an illegal character """,
        options = '--bad-filename-chars-sub',
        default = '-',
    )

    files['directory'] = StringOption(
        """ Directory to put output files into """,
        options = '--dir -d',
        default = '$jobname',
    )

    #
    # Images
    #

    images = config.addSection('images')

    class ImageScaleOption(DictOption[float]):
        @classmethod
        def entryFromString(cls, entry: str) -> float:
            return float(entry)

        def registerArgparse(self, group: ArgumentGroup):
            group.add_argument(*self.options, dest=self.name, help=self.description, action='append', nargs=2, metavar=("NODE", "VALUE"))

    images['scales'] = ImageScaleOption(
        """ Set image scale for given node name """,
        options = '--scales',
        default = {}
    )

    images['base-url'] = StringOption(
        """ Base URL for all images """,
        options = '--image-base-url',
        default = '',
    )

    images['enabled'] = BooleanOption(
        """ Enable image generation """,
        options = '--enable-images !--disable-images',
        default = True,
    )

    images['imager'] = StringOption(
        """ LaTeX to image program """,
        options = '--imager',
        default = 'gspdfpng pdftoppm dvipng dvi2bitmap gsdvipng OSXCoreGraphics',
    )

    images['vector-imager'] = StringOption(
        """ LaTeX to vector image program """,
        options = '--vector-imager',
        default = 'pdf2svg dvisvgm',
    )

    images['filenames'] = StringOption(
        """ Template for image filenames """,
        options = '--image-filenames',
        default = 'images/img-$num(4)',
    )

    images['baseline-padding'] = IntegerOption(
        """ Amount to pad the image below the baseline """,
        options = '--image-baseline-padding',
        default = 0,
    )

    images['scale-factor'] = FloatOption(
        """ Factor to scale externally included images by """,
        options = '--image-scale-factor',
        default = 1.0,
    )

    images['vector-compiler'] = StringOption(
        """ LaTeX command to use when compiling image document with vector imager""",
        options = '--vector-image-compiler',
        default = '',
    )

    images['compiler'] = StringOption(
        """ LaTeX command to use when compiling image document """,
        options = '--image-compiler',
        default = '',
    )

    images['cache'] = BooleanOption(
        """  Enable image caching between runs """,
        options = '--enable-image-cache !--disable-image-cache',
        default = False,
    )

    images['save-file'] = BooleanOption(
        """ Should the temporary images.tex file be saved for debugging? """,
        options = '--save-image-file !--delete-image-file',
        default = False,
    )

    images['transparent'] = BooleanOption(
        """ Specifies whether the image backgrounds should be transparent or not """,
        options = '--transparent-images !--opaque-images',
        default = False,
    )

    images['resolution'] = IntegerOption(
        """ Resolution of images document """,
        options = '--image-resolution',
        default = 0,
    )

    #
    # Document
    #

    doc = config.addSection('document', "Document Options")

    doc['base-url'] = StringOption(
        """ Base URL for inter-node links """,
        options = '--base-url',
        default = '',
    )

    doc['title'] = StringOption(
        """
        Title for the document

        This option specifies a title to use instead of the title
        specified in the LaTeX document.

        """,
        options = '--title',
        default = '',
    )

    doc['toc-depth'] = IntegerOption(
        """ Number of levels to display in the table of contents """,
        options = '--toc-depth',
        default = 3,
    )

    doc['toc-non-files'] = BooleanOption(
        """ Display sections that do not create files in the table of contents """,
        options = '--toc-non-files',
        default = False,
    )

    doc['sec-num-depth'] = IntegerOption(
        """ Maximum section depth to display section numbers """,
        options = '--sec-num-depth',
        default = 2,
    )

    doc['index-columns'] = IntegerOption(
        """ Number of columns to split the index entries into """,
        options = '--index-columns',
        default = 2,
    )

    doc['lang-terms'] = MultiStringOption(
        """ A list of files that contain language terms """,
        options = '--lang-terms',
        default = [],
    )

    doc['disable-charsub'] = MultiStringOption(
        """A list of characters to not perform character substitutions""",
        options = "--disable-charsub",
        default = []
    )

    #
    # Logging
    #

    logging = config.addSection('logging', "Logging Options")

    class LogOption(DictOption[str]):
        @classmethod
        def entryFromString(cls, entry: str) -> str:
            return entry

        def registerArgparse(self, group: ArgumentGroup):
            group.add_argument(*self.options, dest=self.name, help=self.description, action='append', nargs=2, metavar=("NAME", "LEVEL"))

    logging["logging"] = LogOption("Log levels", options = "--logging", default = {})

    if loadConfigFiles:
        config.read(['~/.plasTeXrc', '/usr/local/etc/plasTeXrc', os.path.join(os.path.dirname(__file__), 'plasTeXrc')])

    return config