1try: 2 import locale 3 locale.setlocale(locale.LC_ALL, '') 4except: 5 pass 6 7 8# try to import a litre_config.py file. 9try: 10 import litre_config as config 11except: 12 class config: pass 13 14import sys 15try: # if the user has set up docutils_root in his config, add it to the PYTHONPATH. 16 sys.path += ['%s/docutils' % config.docutils_root 17 , '%s/docutils/extras' % config.docutils_root] 18except: pass 19 20import docutils.writers 21import cplusplus 22import os 23 24from docutils.core import publish_cmdline, default_description 25 26description = ('Literate programming from ReStructuredText ' 27 'sources. ' + default_description) 28 29def _pop_option(prefix): 30 found = None 31 for opt in sys.argv: 32 if opt.startswith(prefix): 33 sys.argv = [ x for x in sys.argv if x != opt ] 34 found = opt 35 if prefix.endswith('='): 36 found = opt[len(prefix):] 37 return found 38 39 40dump_dir = _pop_option('--dump_dir=') 41max_output_lines = _pop_option('--max_output_lines=') 42 43if dump_dir: 44 45 cplusplus.Writer.translator = cplusplus.DumpTranslator 46 if _pop_option('--workaround'): 47 cplusplus.Writer.translator = cplusplus.WorkaroundTranslator 48 config.includes.insert(0, os.path.join(os.path.split(dump_dir)[0], 'patches')) 49 50 config.dump_dir = os.path.abspath(dump_dir) 51 if _pop_option('--cleanup_source'): 52 config.line_hash = None 53 54 if not os.path.exists(config.dump_dir): 55 os.makedirs(config.dump_dir) 56 57if max_output_lines: 58 config.max_output_lines = int(max_output_lines) 59 60config.bjam_options = _pop_option('--bjam=') 61 62config.includes = [] 63 64publish_cmdline( 65 writer=cplusplus.Writer(config), 66 description=description 67 ) 68