mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Hush the nanny.
This commit is contained in:
parent
5d64421c23
commit
77878413ba
3 changed files with 78 additions and 78 deletions
|
@ -12,19 +12,19 @@ for dir in sys.path:
|
||||||
# Look for *.py files
|
# Look for *.py files
|
||||||
filelist=glob.glob(os.path.join(dir, '*.py'))
|
filelist=glob.glob(os.path.join(dir, '*.py'))
|
||||||
for file in filelist:
|
for file in filelist:
|
||||||
path, file = os.path.split(file)
|
path, file = os.path.split(file)
|
||||||
base, ext=os.path.splitext(file)
|
base, ext=os.path.splitext(file)
|
||||||
modules[string.lower(base)]=base
|
modules[string.lower(base)]=base
|
||||||
|
|
||||||
# Look for shared library files
|
# Look for shared library files
|
||||||
filelist=(glob.glob(os.path.join(dir, '*.so')) +
|
filelist=(glob.glob(os.path.join(dir, '*.so')) +
|
||||||
glob.glob(os.path.join(dir, '*.sl')) +
|
glob.glob(os.path.join(dir, '*.sl')) +
|
||||||
glob.glob(os.path.join(dir, '*.o')) )
|
glob.glob(os.path.join(dir, '*.o')) )
|
||||||
for file in filelist:
|
for file in filelist:
|
||||||
path, file = os.path.split(file)
|
path, file = os.path.split(file)
|
||||||
base, ext=os.path.splitext(file)
|
base, ext=os.path.splitext(file)
|
||||||
if base[-6:]=='module': base=base[:-6]
|
if base[-6:]=='module': base=base[:-6]
|
||||||
modules[string.lower(base)]=base
|
modules[string.lower(base)]=base
|
||||||
|
|
||||||
# Minor oddity: the types module is documented in libtypes2.tex
|
# Minor oddity: the types module is documented in libtypes2.tex
|
||||||
if modules.has_key('types'):
|
if modules.has_key('types'):
|
||||||
|
@ -53,7 +53,7 @@ modules=mlist
|
||||||
print """\documentstyle[twoside,11pt,myformat]{report}
|
print """\documentstyle[twoside,11pt,myformat]{report}
|
||||||
\\title{Python Library Reference}
|
\\title{Python Library Reference}
|
||||||
\\input{boilerplate}
|
\\input{boilerplate}
|
||||||
\\makeindex % tell \\index to actually write the .idx file
|
\\makeindex % tell \\index to actually write the .idx file
|
||||||
\\begin{document}
|
\\begin{document}
|
||||||
\\pagenumbering{roman}
|
\\pagenumbering{roman}
|
||||||
\\maketitle
|
\\maketitle
|
||||||
|
@ -69,5 +69,5 @@ for modname in mlist:
|
||||||
print "\\input{lib%s}" % (modname,)
|
print "\\input{lib%s}" % (modname,)
|
||||||
|
|
||||||
# Write the end
|
# Write the end
|
||||||
print """\\input{custlib.ind} % Index
|
print """\\input{custlib.ind} % Index
|
||||||
\\end{document}"""
|
\\end{document}"""
|
||||||
|
|
|
@ -30,14 +30,14 @@ def cmp_entries(e1, e2, lower=string.lower):
|
||||||
|
|
||||||
def dump_entries(write, entries):
|
def dump_entries(write, entries):
|
||||||
if len(entries) == 1:
|
if len(entries) == 1:
|
||||||
write(" \\item %s (%s)%s\n" % entries[0])
|
write(" \\item %s (%s)%s\n" % entries[0])
|
||||||
return
|
return
|
||||||
write(" \item %s\n" % entries[0][0])
|
write(" \item %s\n" % entries[0][0])
|
||||||
# now sort these in a case insensitive manner:
|
# now sort these in a case insensitive manner:
|
||||||
if len(entries) > 0:
|
if len(entries) > 0:
|
||||||
entries.sort(cmp_entries)
|
entries.sort(cmp_entries)
|
||||||
for xxx, subitem, pages in entries:
|
for xxx, subitem, pages in entries:
|
||||||
write(" \subitem %s%s\n" % (subitem, pages))
|
write(" \subitem %s%s\n" % (subitem, pages))
|
||||||
|
|
||||||
|
|
||||||
breakable_re = re.compile(
|
breakable_re = re.compile(
|
||||||
|
@ -56,31 +56,31 @@ def process(ifn, ofn=None):
|
||||||
match = breakable_re.match
|
match = breakable_re.match
|
||||||
write = ofp.write
|
write = ofp.write
|
||||||
while 1:
|
while 1:
|
||||||
line = ifp.readline()
|
line = ifp.readline()
|
||||||
if not line:
|
if not line:
|
||||||
break
|
break
|
||||||
m = match(line)
|
m = match(line)
|
||||||
if m:
|
if m:
|
||||||
entry = m.group(1, 2, 3)
|
entry = m.group(1, 2, 3)
|
||||||
if entries and entries[-1][0] != entry[0]:
|
if entries and entries[-1][0] != entry[0]:
|
||||||
dump_entries(write, entries)
|
dump_entries(write, entries)
|
||||||
entries = []
|
entries = []
|
||||||
entries.append(entry)
|
entries.append(entry)
|
||||||
elif entries:
|
elif entries:
|
||||||
dump_entries(write, entries)
|
dump_entries(write, entries)
|
||||||
entries = []
|
entries = []
|
||||||
write(line)
|
write(line)
|
||||||
else:
|
else:
|
||||||
write(line)
|
write(line)
|
||||||
del write
|
del write
|
||||||
del match
|
del match
|
||||||
ifp.close()
|
ifp.close()
|
||||||
data = ofp.getvalue()
|
data = ofp.getvalue()
|
||||||
ofp.close()
|
ofp.close()
|
||||||
if ofn == "-":
|
if ofn == "-":
|
||||||
ofp = sys.stdout
|
ofp = sys.stdout
|
||||||
else:
|
else:
|
||||||
ofp = open(ofn, "w")
|
ofp = open(ofn, "w")
|
||||||
ofp.write(data)
|
ofp.write(data)
|
||||||
ofp.close()
|
ofp.close()
|
||||||
|
|
||||||
|
@ -90,8 +90,8 @@ def main():
|
||||||
outfile = None
|
outfile = None
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "o:")
|
opts, args = getopt.getopt(sys.argv[1:], "o:")
|
||||||
for opt, val in opts:
|
for opt, val in opts:
|
||||||
if opt in ("-o", "--output"):
|
if opt in ("-o", "--output"):
|
||||||
outfile = val
|
outfile = val
|
||||||
filename = args[0]
|
filename = args[0]
|
||||||
outfile = outfile or filename
|
outfile = outfile or filename
|
||||||
process(filename, outfile)
|
process(filename, outfile)
|
||||||
|
|
|
@ -23,7 +23,7 @@ cline_re = r"""^
|
||||||
\\contentsline\ \{([a-z]*)} # type of section in $1
|
\\contentsline\ \{([a-z]*)} # type of section in $1
|
||||||
\{(?:\\numberline\ \{([0-9.A-Z]+)})? # section number
|
\{(?:\\numberline\ \{([0-9.A-Z]+)})? # section number
|
||||||
(.*)} # title string
|
(.*)} # title string
|
||||||
\{(\d+)}$""" # page number
|
\{(\d+)}$""" # page number
|
||||||
|
|
||||||
cline_rx = re.compile(cline_re, re.VERBOSE)
|
cline_rx = re.compile(cline_re, re.VERBOSE)
|
||||||
|
|
||||||
|
@ -50,34 +50,34 @@ def parse_toc(fp, bigpart=None):
|
||||||
level = bigpart or 'chapter'
|
level = bigpart or 'chapter'
|
||||||
lineno = 0
|
lineno = 0
|
||||||
while 1:
|
while 1:
|
||||||
line = fp.readline()
|
line = fp.readline()
|
||||||
if not line:
|
if not line:
|
||||||
break
|
break
|
||||||
lineno = lineno + 1
|
lineno = lineno + 1
|
||||||
m = cline_rx.match(line)
|
m = cline_rx.match(line)
|
||||||
if m:
|
if m:
|
||||||
stype, snum, title, pageno = m.group(1, 2, 3, 4)
|
stype, snum, title, pageno = m.group(1, 2, 3, 4)
|
||||||
title = clean_title(title)
|
title = clean_title(title)
|
||||||
entry = (stype, snum, title, string.atoi(pageno), [])
|
entry = (stype, snum, title, string.atoi(pageno), [])
|
||||||
if stype == level:
|
if stype == level:
|
||||||
toc.append(entry)
|
toc.append(entry)
|
||||||
else:
|
else:
|
||||||
if stype not in INCLUDED_LEVELS:
|
if stype not in INCLUDED_LEVELS:
|
||||||
# we don't want paragraphs & subparagraphs
|
# we don't want paragraphs & subparagraphs
|
||||||
continue
|
continue
|
||||||
direction = _transition_map[(level, stype)]
|
direction = _transition_map[(level, stype)]
|
||||||
if direction == OUTER_TO_INNER:
|
if direction == OUTER_TO_INNER:
|
||||||
toc = toc[-1][-1]
|
toc = toc[-1][-1]
|
||||||
stack.insert(0, toc)
|
stack.insert(0, toc)
|
||||||
toc.append(entry)
|
toc.append(entry)
|
||||||
else:
|
else:
|
||||||
for i in range(direction):
|
for i in range(direction):
|
||||||
del stack[0]
|
del stack[0]
|
||||||
toc = stack[0]
|
toc = stack[0]
|
||||||
toc.append(entry)
|
toc.append(entry)
|
||||||
level = stype
|
level = stype
|
||||||
else:
|
else:
|
||||||
sys.stderr.write("l.%s: " + line)
|
sys.stderr.write("l.%s: " + line)
|
||||||
return top
|
return top
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,33 +91,33 @@ def clean_title(title):
|
||||||
title = hackscore_rx.sub(r"\\_", title)
|
title = hackscore_rx.sub(r"\\_", title)
|
||||||
pos = 0
|
pos = 0
|
||||||
while 1:
|
while 1:
|
||||||
m = title_rx.search(title, pos)
|
m = title_rx.search(title, pos)
|
||||||
if m:
|
if m:
|
||||||
start = m.start()
|
start = m.start()
|
||||||
if title[start:start+15] != "\\textunderscore":
|
if title[start:start+15] != "\\textunderscore":
|
||||||
title = title[:start] + title[m.end():]
|
title = title[:start] + title[m.end():]
|
||||||
pos = start + 1
|
pos = start + 1
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
title = string.translate(title, title_trans, "{}")
|
title = string.translate(title, title_trans, "{}")
|
||||||
return title
|
return title
|
||||||
|
|
||||||
|
|
||||||
def write_toc(toc, fp):
|
def write_toc(toc, fp):
|
||||||
for entry in toc:
|
for entry in toc:
|
||||||
write_toc_entry(entry, fp, 0)
|
write_toc_entry(entry, fp, 0)
|
||||||
|
|
||||||
def write_toc_entry(entry, fp, layer):
|
def write_toc_entry(entry, fp, layer):
|
||||||
stype, snum, title, pageno, toc = entry
|
stype, snum, title, pageno, toc = entry
|
||||||
s = "\\pdfoutline goto name{page%03d}" % pageno
|
s = "\\pdfoutline goto name{page%03d}" % pageno
|
||||||
if toc:
|
if toc:
|
||||||
s = "%s count -%d" % (s, len(toc))
|
s = "%s count -%d" % (s, len(toc))
|
||||||
if snum:
|
if snum:
|
||||||
title = "%s %s" % (snum, title)
|
title = "%s %s" % (snum, title)
|
||||||
s = "%s {%s}\n" % (s, title)
|
s = "%s {%s}\n" % (s, title)
|
||||||
fp.write(s)
|
fp.write(s)
|
||||||
for entry in toc:
|
for entry in toc:
|
||||||
write_toc_entry(entry, fp, layer + 1)
|
write_toc_entry(entry, fp, layer + 1)
|
||||||
|
|
||||||
|
|
||||||
def process(ifn, ofn, bigpart=None):
|
def process(ifn, ofn, bigpart=None):
|
||||||
|
@ -129,13 +129,13 @@ def main():
|
||||||
bigpart = None
|
bigpart = None
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "c:")
|
opts, args = getopt.getopt(sys.argv[1:], "c:")
|
||||||
if opts:
|
if opts:
|
||||||
bigpart = opts[0][1]
|
bigpart = opts[0][1]
|
||||||
if not args:
|
if not args:
|
||||||
usage()
|
usage()
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
for filename in args:
|
for filename in args:
|
||||||
base, ext = os.path.splitext(filename)
|
base, ext = os.path.splitext(filename)
|
||||||
ext = ext or ".toc"
|
ext = ext or ".toc"
|
||||||
process(base + ext, base + ".bkm", bigpart)
|
process(base + ext, base + ".bkm", bigpart)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue