summaryrefslogtreecommitdiffstats
path: root/Doc/tools/toc2bkm.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>1998-03-07 15:34:50 (GMT)
committerFred Drake <fdrake@acm.org>1998-03-07 15:34:50 (GMT)
commit473a90e8310d9a7055c8980f82ef1476daaddccd (patch)
tree646a14b8c6e225b7bf075428248ee263dc006fea /Doc/tools/toc2bkm.py
parentcd05ca97625b26f086528141c95b34fe5d97b235 (diff)
downloadcpython-473a90e8310d9a7055c8980f82ef1476daaddccd.zip
cpython-473a90e8310d9a7055c8980f82ef1476daaddccd.tar.gz
cpython-473a90e8310d9a7055c8980f82ef1476daaddccd.tar.bz2
Allow the user to specify the "biggest" section type from the command line;
default is "chapter". Use 'python toc2bkm.py -c section' to use with Python HOWTO documents.
Diffstat (limited to 'Doc/tools/toc2bkm.py')
-rwxr-xr-xDoc/tools/toc2bkm.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/Doc/tools/toc2bkm.py b/Doc/tools/toc2bkm.py
index dd74fd4..2b96312 100755
--- a/Doc/tools/toc2bkm.py
+++ b/Doc/tools/toc2bkm.py
@@ -6,6 +6,7 @@ The output file has an extension of '.bkm' instead of '.out', since hyperref
already uses that extension. Let's avoid clashing.
"""
+import getopt
import os
import re
import string
@@ -38,10 +39,10 @@ _transition_map = {
('subsubsection', 'chapter'): 3,
}
-def parse_toc(fp):
+def parse_toc(fp, bigpart=None):
toc = top = []
stack = [toc]
- level = 'chapter'
+ level = bigpart or 'chapter'
lineno = 0
while 1:
line = fp.readline()
@@ -105,10 +106,18 @@ def write_toc_entry(entry, fp, layer):
def main():
- base, ext = os.path.splitext(sys.argv[1])
- ext = ext or ".toc"
- toc = parse_toc(open(base + ext))
- write_toc(toc, open(base + ".bkm", "w"))
+ bigpart = None
+ opts, args = getopt.getopt(sys.argv[1:], "c:")
+ if opts:
+ bigpart = opts[0][1]
+ if not args:
+ usage()
+ sys.exit(2)
+ for filename in args:
+ base, ext = os.path.splitext(filename)
+ ext = ext or ".toc"
+ toc = parse_toc(open(base + ext), bigpart)
+ write_toc(toc, open(base + ".bkm", "w"))
if __name__ == "__main__":