Fix #338: re.sub() flag argument at wrong position.
[docutils.git] / sandbox / py-rest-doc / converter / filenamemap.py
blob6f556d83a8181e7d7e18a6ee2b1c6fcb2b376e1c
1 # -*- coding: utf-8 -*-
2 """
3 Map LaTeX filenames to ReST filenames
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 :copyright: 2007 by Georg Brandl.
7 :license: Python license.
8 """
10 # '' means: use same name, strip prefix if applicable.
11 # None means: don't translate at all.
13 _mapping = {
14 'lib': {
15 '__newname__' : 'modules',
17 'asttable': '',
18 'compiler': '',
19 'distutils': '',
20 'email': '',
21 'emailcharsets': 'email.charset',
22 'emailencoders': 'email.encoders',
23 'emailexc': 'email.errors',
24 'emailgenerator': 'email.generator',
25 'emailheaders': 'email.header',
26 'emailiter': 'email.iterators',
27 'emailmessage': 'email.message',
28 'emailmimebase': 'email.mime',
29 'emailparser': 'email.parser',
30 'emailutil': 'email.util',
31 'libaifc': '',
32 'libanydbm': '',
33 'libarray': '',
34 'libascii': 'curses.ascii',
35 'libast': '',
36 'libasynchat': '',
37 'libasyncore': '',
38 'libatexit': '',
39 'libaudioop': '',
40 'libbase64': '',
41 'libbasehttp': 'basehttpserver',
42 'libbastion': '',
43 'libbinascii': '',
44 'libbinhex': '',
45 'libbisect': '',
46 'libbltin': '__builtin__',
47 'libbsddb': '',
48 'libbz2': '',
49 'libcalendar': '',
50 'libcfgparser': 'configparser',
51 'libcgihttp': 'cgihttpserver',
52 'libcgi': '',
53 'libcgitb': '',
54 'libchunk': '',
55 'libcmath': '',
56 'libcmd': '',
57 'libcodecs': '',
58 'libcodeop': '',
59 'libcode': '',
60 'libcollections': '',
61 'libcolorsys': '',
62 'libcommands': '',
63 'libcompileall': '',
64 'libcontextlib': '',
65 'libcookielib': '',
66 'libcookie': '',
67 'libcopyreg': 'copy_reg',
68 'libcopy': '',
69 'libcrypt': '',
70 'libcsv': '',
71 'libctypes': '',
72 'libcursespanel': 'curses.panel',
73 'libcurses': '',
74 'libdatetime': '',
75 'libdbhash': '',
76 'libdbm': '',
77 'libdecimal': '',
78 'libdifflib': '',
79 'libdircache': '',
80 'libdis': '',
81 'libdl': '',
82 'libdoctest': '',
83 'libdocxmlrpc': 'docxmlrpcserver',
84 'libdumbdbm': '',
85 'libdummythreading': 'dummy_threading',
86 'libdummythread': 'dummy_thread',
87 'liberrno': '',
88 'libetree': 'xml.etree.elementtree',
89 'libfcntl': '',
90 'libfilecmp': '',
91 'libfileinput': '',
92 'libfnmatch': '',
93 'libformatter': '',
94 'libfpectl': '',
95 'libfpformat': '',
96 'libftplib': '',
97 'libfunctools': '',
98 'libfuture': '__future__',
99 'libgc': '',
100 'libgdbm': '',
101 'libgetopt': '',
102 'libgetpass': '',
103 'libgettext': '',
104 'libglob': '',
105 'libgrp': '',
106 'libgzip': '',
107 'libhashlib': '',
108 'libheapq': '',
109 'libhmac': '',
110 'libhotshot': '',
111 'libhtmllib': '',
112 'libhtmlparser': '',
113 'libhttplib': '',
114 'libimageop': '',
115 'libimaplib': '',
116 'libimgfile': '',
117 'libimghdr': '',
118 'libimp': '',
119 'libinspect': '',
120 'libitertools': '',
121 'libjpeg': '',
122 'libkeyword': '',
123 'liblinecache': '',
124 'liblocale': '',
125 'liblogging': '',
126 'libmailbox': '',
127 'libmailcap': '',
128 'libmain': '__main__',
129 'libmarshal': '',
130 'libmath': '',
131 'libmd5': '',
132 'libmhlib': '',
133 'libmimetools': '',
134 'libmimetypes': '',
135 'libmimewriter': '',
136 'libmimify': '',
137 'libmmap': '',
138 'libmodulefinder': '',
139 'libmsilib': '',
140 'libmsvcrt': '',
141 'libmultifile': '',
142 'libmutex': '',
143 'libnetrc': '',
144 'libnew': '',
145 'libnis': '',
146 'libnntplib': '',
147 'liboperator': '',
148 'liboptparse': '',
149 'libos': '',
150 'libossaudiodev': '',
151 'libparser': '',
152 'libpdb': '',
153 'libpickle': '',
154 'libpickletools': '',
155 'libpipes': '',
156 'libpkgutil': '',
157 'libplatform': '',
158 'libpopen2': '',
159 'libpoplib': '',
160 'libposixpath': 'os.path',
161 'libposix': '',
162 'libpprint': '',
163 'libprofile': '',
164 'libpty': '',
165 'libpwd': '',
166 'libpyclbr': '',
167 'libpycompile': 'py_compile',
168 'libpydoc': '',
169 'libpyexpat': '',
170 'libqueue': '',
171 'libquopri': '',
172 'librandom': '',
173 'libreadline': '',
174 'librepr': '',
175 'libre': '',
176 'libresource': '',
177 'librexec': '',
178 'librfc822': '',
179 'librlcompleter': '',
180 'librobotparser': '',
181 'librunpy': '',
182 'libsched': '',
183 'libselect': '',
184 'libsets': '',
185 'libsgmllib': '',
186 'libsha': '',
187 'libshelve': '',
188 'libshlex': '',
189 'libshutil': '',
190 'libsignal': '',
191 'libsimplehttp': 'simplehttpserver',
192 'libsimplexmlrpc': 'simplexmlrpcserver',
193 'libsite': '',
194 'libsmtpd': '',
195 'libsmtplib': '',
196 'libsndhdr': '',
197 'libsocket': '',
198 'libsocksvr': 'socketserver',
199 'libspwd': '',
200 'libsqlite3': '',
201 'libstat': '',
202 'libstatvfs': '',
203 'libstringio': '',
204 'libstringprep': '',
205 'libstring': '',
206 'libstruct': '',
207 'libsunaudio': '',
208 'libsunau': '',
209 'libsubprocess': '',
210 'libsymbol': '',
211 'libsyslog': '',
212 'libsys': '',
213 'libtabnanny': '',
214 'libtarfile': '',
215 'libtelnetlib': '',
216 'libtempfile': '',
217 'libtermios': '',
218 'libtest': '',
219 'libtextwrap': '',
220 'libthreading': '',
221 'libthread': '',
222 'libtimeit': '',
223 'libtime': '',
224 'libtokenize': '',
225 'libtoken': '',
226 'libtraceback': '',
227 'libtrace': '',
228 'libtty': '',
229 'libturtle': '',
230 'libtypes': '',
231 'libunicodedata': '',
232 'libunittest': '',
233 'liburllib2': '',
234 'liburllib': '',
235 'liburlparse': '',
236 'libuserdict': '',
237 'libuser': '',
238 'libuuid': '',
239 'libuu': '',
240 'libwarnings': '',
241 'libwave': '',
242 'libweakref': '',
243 'libwebbrowser': '',
244 'libwhichdb': '',
245 'libwinreg': '_winreg',
246 'libwinsound': '',
247 'libwsgiref': '',
248 'libxdrlib': '',
249 'libxmllib': '',
250 'libxmlrpclib': '',
251 'libzipfile': '',
252 'libzipimport': '',
253 'libzlib': '',
254 'tkinter': '',
255 'xmldomminidom': 'xml.dom.minidom',
256 'xmldompulldom': 'xml.dom.pulldom',
257 'xmldom': 'xml.dom',
258 'xmletree': 'xml.etree',
259 'xmlsaxhandler': 'xml.sax.handler',
260 'xmlsaxreader': 'xml.sax.reader',
261 'xmlsax': 'xml.sax',
262 'xmlsaxutils': 'xml.sax.utils',
263 'libal': '',
264 'libcd': '',
265 'libfl': '',
266 'libfm': '',
267 'libgl': '',
268 'libposixfile': '',
270 # specials
271 'libundoc': '',
272 'libintro': '',
274 # -> ref
275 'libconsts': 'reference/consts',
276 'libexcs': 'reference/exceptions',
277 'libfuncs': 'reference/functions',
278 'libobjs': 'reference/objects',
279 'libstdtypes': 'reference/stdtypes',
281 # mainfiles
282 'lib': None,
283 'mimelib': None,
285 # obsolete
286 'libni': None,
287 'libcmpcache': None,
288 'libcmp': None,
290 # chapter overviews
291 'fileformats': '',
292 'filesys': '',
293 'frameworks': '',
294 'i18n': '',
295 'internet': '',
296 'ipc': '',
297 'language': '',
298 'archiving': '',
299 'custominterp': '',
300 'datatypes': '',
301 'development': '',
302 'markup': '',
303 'modules': '',
304 'netdata': '',
305 'numeric': '',
306 'persistence': '',
307 'windows': '',
308 'libsun': '',
309 'libmm': '',
310 'liballos': '',
311 'libcrypto': '',
312 'libsomeos': '',
313 'libsgi': '',
314 'libmisc': '',
315 'libpython': '',
316 'librestricted': '',
317 'libstrings': '',
318 'libunix': '',
321 'ref': {
322 '__newname__': 'reference',
323 'ref': None,
324 'ref1': 'introduction',
325 'ref2': 'lexical_analysis',
326 'ref3': 'datamodel',
327 'ref4': 'executionmodel',
328 'ref5': 'expressions',
329 'ref6': 'simple_stmts',
330 'ref7': 'compound_stmts',
331 'ref8': 'toplevel_components',
334 'tut': {
335 '__newname__': 'tutorial',
336 '__labelprefix__': 'tut-',
337 'tut': 'tutorial:split',
338 'glossary': 'glossary',
341 'api': {
342 '__newname__': 'c-api',
343 '__defaulthighlightlang__': 'c',
344 'api': None,
346 'abstract': '',
347 'concrete': '',
348 'exceptions': '',
349 'init': '',
350 'intro': '',
351 'memory': '',
352 'newtypes': '',
353 'refcounting': '',
354 'utilities': '',
355 'veryhigh': '',
358 'ext': {
359 '__newname__': 'extending',
360 '__defaulthighlightlang__': 'c',
361 'ext': None,
363 'building': '',
364 'embedding': '',
365 'extending': 'extending',
366 'newtypes': '',
367 'windows': '',
370 'dist': {
371 '__newname__': 'distutils',
372 'dist': 'distutils:split',
373 'sysconfig': '',
376 'mac': {
377 '__newname__': 'macmodules',
378 'mac': None,
380 'libaepack': 'aepack',
381 'libaetools': 'aetools',
382 'libaetypes': 'aetypes',
383 'libautogil': 'autogil',
384 'libcolorpicker': 'colorpicker',
385 'libframework': 'framework',
386 'libgensuitemodule': 'gensuitemodule',
387 'libmacic': 'macic',
388 'libmacos': 'macos',
389 'libmacostools': 'macostools',
390 'libmac': 'mac',
391 'libmacui': 'macui',
392 'libminiae': 'miniae',
393 'libscrap': 'scrap',
394 'scripting': '',
395 'toolbox': '',
396 'undoc': '',
397 'using': '',
401 'inst': {
402 '__newname__': 'install',
403 '__defaulthighlightlang__': 'none',
404 'inst': 'index',
407 'whatsnew': {
408 '__newname__': 'whatsnew',
409 'whatsnew20': '2.0',
410 'whatsnew21': '2.1',
411 'whatsnew22': '2.2',
412 'whatsnew23': '2.3',
413 'whatsnew24': '2.4',
414 'whatsnew25': '2.5',
415 'whatsnew26': '2.6',
418 'commontex': {
419 '__newname__': '',
420 'boilerplate': None,
421 'patchlevel': None,
422 'copyright': '',
423 'license': '',
424 'reportingbugs': 'bugs',
428 fn_mapping = {}
430 for dir, files in _mapping.iteritems():
431 newmap = fn_mapping[dir] = {}
432 for fn in files:
433 if not fn.startswith('_') and files[fn] == '':
434 if fn.startswith(dir):
435 newmap[fn] = fn[len(dir):]
436 else:
437 newmap[fn] = fn
438 else:
439 newmap[fn] = files[fn]
442 # new directories to create
443 dirs_to_make = [
444 'c-api',
445 'data',
446 'distutils',
447 'documenting',
448 'extending',
449 'includes',
450 'includes/sqlite3',
451 'install',
452 'macmodules',
453 'modules',
454 'reference',
455 'tutorial',
456 'whatsnew',
459 # includefiles for \verbatiminput and \input
460 includes_mapping = {
461 '../../Parser/Python.asdl': None, # XXX
462 '../../Lib/test/exception_hierarchy.txt': None,
463 'emailmessage': 'email.message.rst',
464 'emailparser': 'email.parser.rst',
465 'emailgenerator': 'email.generator.rst',
466 'emailmimebase': 'email.mime.rst',
467 'emailheaders': 'email.header.rst',
468 'emailcharsets': 'email.charset.rst',
469 'emailencoders': 'email.encoders.rst',
470 'emailexc': 'email.errors.rst',
471 'emailutil': 'email.util.rst',
472 'emailiter': 'email.iterators.rst',
475 # new files to copy from converter/newfiles
476 newfiles_mapping = {
477 'conf.py': 'conf.py',
478 'TODO': 'TODO',
480 'ref_index.rst': 'reference/index.rst',
481 'tutorial_index.rst': 'tutorial/index.rst',
482 'modules_index.rst': 'modules/index.rst',
483 'mac_index.rst': 'macmodules/index.rst',
484 'ext_index.rst': 'extending/index.rst',
485 'api_index.rst': 'c-api/index.rst',
486 'dist_index.rst': 'distutils/index.rst',
487 'contents.rst': 'contents.rst',
488 'about.rst': 'about.rst',
490 'doc.rst': 'documenting/index.rst',
491 'doc_intro.rst': 'documenting/intro.rst',
492 'doc_style.rst': 'documenting/style.rst',
493 'doc_sphinx.rst': 'documenting/sphinx.rst',
494 'doc_rest.rst': 'documenting/rest.rst',
495 'doc_markup.rst': 'documenting/markup.rst',
498 # copy files from the old doc tree
499 copyfiles_mapping = {
500 'api/refcounts.dat': 'data',
501 'lib/email-*.py': 'includes',
502 'lib/minidom-example.py': 'includes',
503 'lib/tzinfo-examples.py': 'includes',
504 'lib/sqlite3/*.py': 'includes/sqlite3',
505 'ext/*.c': 'includes',
506 'ext/*.py': 'includes',
507 'commontex/typestruct.h': 'includes',
510 # files to rename
511 rename_mapping = {
512 'tutorial/1_tutorial.rst': None, # delete
513 'tutorial/2_tutorial.rst': 'tutorial/appetite.rst',
514 'tutorial/3_tutorial.rst': 'tutorial/interpreter.rst',
515 'tutorial/4_tutorial.rst': 'tutorial/introduction.rst',
516 'tutorial/5_tutorial.rst': 'tutorial/controlflow.rst',
517 'tutorial/6_tutorial.rst': 'tutorial/datastructures.rst',
518 'tutorial/7_tutorial.rst': 'tutorial/modules.rst',
519 'tutorial/8_tutorial.rst': 'tutorial/inputoutput.rst',
520 'tutorial/9_tutorial.rst': 'tutorial/errors.rst',
521 'tutorial/10_tutorial.rst': 'tutorial/classes.rst',
522 'tutorial/11_tutorial.rst': 'tutorial/stdlib.rst',
523 'tutorial/12_tutorial.rst': 'tutorial/stdlib2.rst',
524 'tutorial/13_tutorial.rst': 'tutorial/whatnow.rst',
525 'tutorial/14_tutorial.rst': 'tutorial/interactive.rst',
526 'tutorial/15_tutorial.rst': 'tutorial/floatingpoint.rst',
527 'tutorial/16_tutorial.rst': None, # delete
529 'distutils/1_distutils.rst': 'distutils/introduction.rst',
530 'distutils/2_distutils.rst': 'distutils/setupscript.rst',
531 'distutils/3_distutils.rst': 'distutils/configfile.rst',
532 'distutils/4_distutils.rst': 'distutils/sourcedist.rst',
533 'distutils/5_distutils.rst': 'distutils/builtdist.rst',
534 'distutils/6_distutils.rst': 'distutils/packageindex.rst',
535 'distutils/7_distutils.rst': 'distutils/uploading.rst',
536 'distutils/8_distutils.rst': 'distutils/examples.rst',
537 'distutils/9_distutils.rst': 'distutils/extending.rst',
538 'distutils/10_distutils.rst': 'distutils/commandref.rst',
539 'distutils/11_distutils.rst': 'distutils/apiref.rst',
542 # toctree entries
543 toctree_mapping = {
544 'mac/scripting': ['gensuitemodule', 'aetools', 'aepack', 'aetypes', 'miniae'],
545 'mac/toolbox': ['colorpicker'],
546 'lib/libstrings': ['string', 're', 'struct', 'difflib', 'stringio', 'textwrap',
547 'codecs', 'unicodedata', 'stringprep', 'fpformat'],
548 'lib/datatypes': ['datetime', 'calendar', 'collections', 'heapq', 'bisect',
549 'array', 'sets', 'sched', 'mutex', 'queue', 'weakref',
550 'userdict', 'types', 'new', 'copy', 'pprint', 'repr'],
551 'lib/numeric': ['math', 'cmath', 'decimal', 'random', 'itertools', 'functools',
552 'operator'],
553 'lib/netdata': ['email', 'mailcap', 'mailbox', 'mhlib', 'mimetools', 'mimetypes',
554 'mimewriter', 'mimify', 'multifile', 'rfc822',
555 'base64', 'binhex', 'binascii', 'quopri', 'uu'],
556 'lib/markup': ['htmlparser', 'sgmllib', 'htmllib', 'pyexpat', 'xml.dom',
557 'xml.dom.minidom', 'xml.dom.pulldom', 'xml.sax', 'xml.sax.handler',
558 'xml.sax.utils', 'xml.sax.reader', 'xml.etree.elementtree'],
559 'lib/fileformats': ['csv', 'configparser', 'robotparser', 'netrc', 'xdrlib'],
560 'lib/libcrypto': ['hashlib', 'hmac', 'md5', 'sha'],
561 'lib/filesys': ['os.path', 'fileinput', 'stat', 'statvfs', 'filecmp',
562 'tempfile', 'glob', 'fnmatch', 'linecache', 'shutil', 'dircache'],
563 'lib/archiving': ['zlib', 'gzip', 'bz2', 'zipfile', 'tarfile'],
564 'lib/persistence': ['pickle', 'copy_reg', 'shelve', 'marshal', 'anydbm',
565 'whichdb', 'dbm', 'gdbm', 'dbhash', 'bsddb', 'dumbdbm',
566 'sqlite3'],
567 'lib/liballos': ['os', 'time', 'optparse', 'getopt', 'logging', 'getpass',
568 'curses', 'curses.ascii', 'curses.panel', 'platform',
569 'errno', 'ctypes'],
570 'lib/libsomeos': ['select', 'thread', 'threading', 'dummy_thread', 'dummy_threading',
571 'mmap', 'readline', 'rlcompleter'],
572 'lib/libunix': ['posix', 'pwd', 'spwd', 'grp', 'crypt', 'dl', 'termios', 'tty',
573 'pty', 'fcntl', 'pipes', 'posixfile', 'resource', 'nis',
574 'syslog', 'commands'],
575 'lib/ipc': ['subprocess', 'socket', 'signal', 'popen2', 'asyncore', 'asynchat'],
576 'lib/internet': ['webbrowser', 'cgi', 'cgitb', 'wsgiref', 'urllib', 'urllib2',
577 'httplib', 'ftplib', 'poplib', 'imaplib',
578 'nntplib', 'smtplib', 'smtpd', 'telnetlib', 'uuid', 'urlparse',
579 'socketserver', 'basehttpserver', 'simplehttpserver',
580 'cgihttpserver', 'cookielib', 'cookie', 'xmlrpclib',
581 'simplexmlrpcserver', 'docxmlrpcserver'],
582 'lib/libmm': ['audioop', 'imageop', 'aifc', 'sunau', 'wave', 'chunk',
583 'colorsys', 'imghdr', 'sndhdr', 'ossaudiodev'],
584 'lib/i18n': ['gettext', 'locale'],
585 'lib/frameworks': ['cmd', 'shlex'],
586 'lib/development': ['pydoc', 'doctest', 'unittest', 'test'],
587 'lib/libpython': ['sys', '__builtin__', '__main__', 'warnings', 'contextlib',
588 'atexit', 'traceback', '__future__', 'gc', 'inspect',
589 'site', 'user', 'fpectl'],
590 'lib/custominterp': ['code', 'codeop'],
591 'lib/librestricted': ['rexec', 'bastion'],
592 'lib/modules': ['imp', 'zipimport', 'pkgutil', 'modulefinder', 'runpy'],
593 'lib/language': ['parser', 'symbol', 'token', 'keyword', 'tokenize',
594 'tabnanny', 'pyclbr', 'py_compile', 'compileall', 'dis',
595 'pickletools', 'distutils'],
596 'lib/compiler': ['ast'],
597 'lib/libmisc': ['formatter'],
598 'lib/libsgi': ['al', 'cd', 'fl', 'fm', 'gl', 'imgfile', 'jpeg'],
599 'lib/libsun': ['sunaudio'],
600 'lib/windows': ['msilib', 'msvcrt', '_winreg', 'winsound'],
603 # map sourcefilename to [pre, post]
604 amendments_mapping = {
605 'license.rst': ['''\
606 .. highlightlang:: none
608 *******************
609 History and License
610 *******************
612 ''', ''],
614 'bugs.rst': ['''\
615 **************
616 Reporting Bugs
617 **************
619 ''', ''],
621 'copyright.rst': ['''\
622 *********
623 Copyright
624 *********
626 ''', ''],
628 'install/index.rst': ['''\
629 .. _install-index:
631 ''', ''],