blob: 15f07baf0e534ff9884ca158af30525dc0a9633d [file] [log] [blame]
Guido van Rossum6cb2ac21997-06-02 17:57:10 +00001# Generate custlib.tex, which is a site-specific library document.
2
3# Phase I: list all the things that can be imported
4
Fred Drake4fe904d2002-10-16 14:59:02 +00005import glob
6import os.path
7import sys
8
9modules = {}
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000010
11for modname in sys.builtin_module_names:
Fred Drake4fe904d2002-10-16 14:59:02 +000012 modules[modname] = modname
Tim Peters3d7d3722004-07-18 06:25:50 +000013
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000014for dir in sys.path:
15 # Look for *.py files
Fred Drake4fe904d2002-10-16 14:59:02 +000016 filelist = glob.glob(os.path.join(dir, '*.py'))
Tim Peters3d7d3722004-07-18 06:25:50 +000017 for file in filelist:
Fred Drake77878412000-10-07 12:50:05 +000018 path, file = os.path.split(file)
Fred Drake4fe904d2002-10-16 14:59:02 +000019 base, ext = os.path.splitext(file)
20 modules[base.lower()] = base
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000021
22 # Look for shared library files
Tim Peters3d7d3722004-07-18 06:25:50 +000023 filelist = (glob.glob(os.path.join(dir, '*.so')) +
Fred Drake4fe904d2002-10-16 14:59:02 +000024 glob.glob(os.path.join(dir, '*.sl')) +
25 glob.glob(os.path.join(dir, '*.o')) )
Tim Peters3d7d3722004-07-18 06:25:50 +000026 for file in filelist:
Fred Drake77878412000-10-07 12:50:05 +000027 path, file = os.path.split(file)
Fred Drake4fe904d2002-10-16 14:59:02 +000028 base, ext = os.path.splitext(file)
29 if base[-6:] == 'module':
30 base = base[:-6]
31 modules[base.lower()] = base
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000032
33# Minor oddity: the types module is documented in libtypes2.tex
34if modules.has_key('types'):
Fred Drake4fe904d2002-10-16 14:59:02 +000035 del modules['types']
36 modules['types2'] = None
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000037
38# Phase II: find all documentation files (lib*.tex)
39# and eliminate modules that don't have one.
40
Fred Drake4fe904d2002-10-16 14:59:02 +000041docs = {}
42filelist = glob.glob('lib*.tex')
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000043for file in filelist:
Fred Drake4fe904d2002-10-16 14:59:02 +000044 modname = file[3:-4]
45 docs[modname] = modname
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000046
Fred Drake4fe904d2002-10-16 14:59:02 +000047mlist = modules.keys()
48mlist = filter(lambda x, docs=docs: docs.has_key(x), mlist)
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000049mlist.sort()
Fred Drake4fe904d2002-10-16 14:59:02 +000050mlist = map(lambda x, docs=docs: docs[x], mlist)
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000051
Fred Drake4fe904d2002-10-16 14:59:02 +000052modules = mlist
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000053
54# Phase III: write custlib.tex
55
56# Write the boilerplate
Tim Peters3d7d3722004-07-18 06:25:50 +000057# XXX should be fancied up.
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000058print """\documentstyle[twoside,11pt,myformat]{report}
59\\title{Python Library Reference}
60\\input{boilerplate}
Fred Drake77878412000-10-07 12:50:05 +000061\\makeindex % tell \\index to actually write the .idx file
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000062\\begin{document}
63\\pagenumbering{roman}
64\\maketitle
65\\input{copyright}
66\\begin{abstract}
67\\noindent This is a customized version of the Python Library Reference.
68\\end{abstract}
69\\pagebreak
70{\\parskip = 0mm \\tableofcontents}
71\\pagebreak\\pagenumbering{arabic}"""
Tim Peters3d7d3722004-07-18 06:25:50 +000072
73for modname in mlist:
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000074 print "\\input{lib%s}" % (modname,)
Tim Peters3d7d3722004-07-18 06:25:50 +000075
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000076# Write the end
Fred Drake77878412000-10-07 12:50:05 +000077print """\\input{custlib.ind} % Index
Guido van Rossum6cb2ac21997-06-02 17:57:10 +000078\\end{document}"""