summaryrefslogtreecommitdiffstats
path: root/src/boost/tools/litre/tool.py
blob: 1533fc33d40f7b2e0e0dc4415ed23730897dd0a8 (plain)
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
try:
    import locale
    locale.setlocale(locale.LC_ALL, '')
except:
    pass


# try to import a litre_config.py file.
try:
    import litre_config as config
except:
    class config: pass
    
import sys
try: # if the user has set up docutils_root in his config, add it to the PYTHONPATH.
    sys.path += ['%s/docutils' % config.docutils_root
                 , '%s/docutils/extras' % config.docutils_root]
except: pass

import docutils.writers
import cplusplus
import os

from docutils.core import publish_cmdline, default_description

description = ('Literate programming from ReStructuredText '
               'sources.  ' + default_description)

def _pop_option(prefix):
    found = None
    for opt in sys.argv:
        if opt.startswith(prefix):
            sys.argv = [ x for x in sys.argv if x != opt ]
            found = opt
            if prefix.endswith('='):
                found = opt[len(prefix):]
    return found


dump_dir = _pop_option('--dump_dir=')
max_output_lines = _pop_option('--max_output_lines=')

if dump_dir:
    
    cplusplus.Writer.translator = cplusplus.DumpTranslator
    if _pop_option('--workaround'):
        cplusplus.Writer.translator = cplusplus.WorkaroundTranslator
        config.includes.insert(0, os.path.join(os.path.split(dump_dir)[0], 'patches'))
        
    config.dump_dir = os.path.abspath(dump_dir)
    if _pop_option('--cleanup_source'):
        config.line_hash = None
        
    if not os.path.exists(config.dump_dir):
        os.makedirs(config.dump_dir)

if max_output_lines:
    config.max_output_lines = int(max_output_lines)

config.bjam_options = _pop_option('--bjam=')

config.includes = []

publish_cmdline(
    writer=cplusplus.Writer(config),
    description=description
    )