1 | # Generate custlib.tex, which is a site-specific library document.
|
---|
2 |
|
---|
3 | # Phase I: list all the things that can be imported
|
---|
4 |
|
---|
5 | import glob
|
---|
6 | import os.path
|
---|
7 | import sys
|
---|
8 |
|
---|
9 | modules = {}
|
---|
10 |
|
---|
11 | for modname in sys.builtin_module_names:
|
---|
12 | modules[modname] = modname
|
---|
13 |
|
---|
14 | for dir in sys.path:
|
---|
15 | # Look for *.py files
|
---|
16 | filelist = glob.glob(os.path.join(dir, '*.py'))
|
---|
17 | for file in filelist:
|
---|
18 | path, file = os.path.split(file)
|
---|
19 | base, ext = os.path.splitext(file)
|
---|
20 | modules[base.lower()] = base
|
---|
21 |
|
---|
22 | # Look for shared library files
|
---|
23 | filelist = (glob.glob(os.path.join(dir, '*.so')) +
|
---|
24 | glob.glob(os.path.join(dir, '*.sl')) +
|
---|
25 | glob.glob(os.path.join(dir, '*.o')) )
|
---|
26 | for file in filelist:
|
---|
27 | path, file = os.path.split(file)
|
---|
28 | base, ext = os.path.splitext(file)
|
---|
29 | if base[-6:] == 'module':
|
---|
30 | base = base[:-6]
|
---|
31 | modules[base.lower()] = base
|
---|
32 |
|
---|
33 | # Minor oddity: the types module is documented in libtypes2.tex
|
---|
34 | if modules.has_key('types'):
|
---|
35 | del modules['types']
|
---|
36 | modules['types2'] = None
|
---|
37 |
|
---|
38 | # Phase II: find all documentation files (lib*.tex)
|
---|
39 | # and eliminate modules that don't have one.
|
---|
40 |
|
---|
41 | docs = {}
|
---|
42 | filelist = glob.glob('lib*.tex')
|
---|
43 | for file in filelist:
|
---|
44 | modname = file[3:-4]
|
---|
45 | docs[modname] = modname
|
---|
46 |
|
---|
47 | mlist = modules.keys()
|
---|
48 | mlist = filter(lambda x, docs=docs: docs.has_key(x), mlist)
|
---|
49 | mlist.sort()
|
---|
50 | mlist = map(lambda x, docs=docs: docs[x], mlist)
|
---|
51 |
|
---|
52 | modules = mlist
|
---|
53 |
|
---|
54 | # Phase III: write custlib.tex
|
---|
55 |
|
---|
56 | # Write the boilerplate
|
---|
57 | # XXX should be fancied up.
|
---|
58 | print """\documentstyle[twoside,11pt,myformat]{report}
|
---|
59 | \\title{Python Library Reference}
|
---|
60 | \\input{boilerplate}
|
---|
61 | \\makeindex % tell \\index to actually write the .idx file
|
---|
62 | \\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}"""
|
---|
72 |
|
---|
73 | for modname in mlist:
|
---|
74 | print "\\input{lib%s}" % (modname,)
|
---|
75 |
|
---|
76 | # Write the end
|
---|
77 | print """\\input{custlib.ind} % Index
|
---|
78 | \\end{document}"""
|
---|