diff options
author | Fred Drake <fdrake@acm.org> | 1999-08-03 17:54:39 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 1999-08-03 17:54:39 (GMT) |
commit | 46ab6dfa89e2d5eeed8f85b40c022161e2493800 (patch) | |
tree | b35aadf7a537a0c7ca7890ea0e86b1be8c3903f5 /Doc/tools | |
parent | 82ebc27357891ec342b8602fb28189751b8d06e6 (diff) | |
download | cpython-46ab6dfa89e2d5eeed8f85b40c022161e2493800.zip cpython-46ab6dfa89e2d5eeed8f85b40c022161e2493800.tar.gz cpython-46ab6dfa89e2d5eeed8f85b40c022161e2493800.tar.bz2 |
Re-write in Python for portability. About 30% slower, but who cares?!
Diffstat (limited to 'Doc/tools')
-rwxr-xr-x | Doc/tools/getpagecounts | 87 |
1 files changed, 61 insertions, 26 deletions
diff --git a/Doc/tools/getpagecounts b/Doc/tools/getpagecounts index f359637..ef14053 100755 --- a/Doc/tools/getpagecounts +++ b/Doc/tools/getpagecounts @@ -1,38 +1,73 @@ -#! /bin/sh -# -*- Ksh -*- -# -# Generate a page count report of the PostScript version of the manuals. +#! /usr/bin/env python +# -*- Python -*- -TOTAL=0 +"""Generate a page count report of the PostScript version of the manuals.""" -getpagecount() { - PAGECOUNT=`grep -c '^%%Page:' $1.ps` - echo "$2 $1.ps ($PAGECOUNT pages)" - TOTAL=`expr $TOTAL + $PAGECOUNT` -} +__version__ = '$Revision$' -cat <<EOF -This is the PostScript version of the standard Python documentation. -If you plan to print this, be aware that some of the documents are -long. The following manuals are included: -EOF +class PageCounter: + def __init__(self): + self.doclist = [] + self.total = 0 + self.title_width = 0 -getpagecount api "Python/C API " -getpagecount ext "Extending and Embedding the Python Interpreter" -getpagecount lib "Python Library Reference " -getpagecount mac "Macintosh Module Reference " -getpagecount ref "Python Reference Manual " -getpagecount tut "Python Tutorial " -getpagecount doc "Documenting Python " + def add_document(self, prefix, title): + count = count_pages(prefix + ".ps") + self.doclist.append((title, prefix, count)) + self.title_width = max(self.title_width, len(title)) + self.total = self.total + count -echo -echo " Total page count: $TOTAL" + def dump(self): + fmt = "%%-%ds (%%s.ps, %%d pages)" % self.title_width + for item in self.doclist: + print fmt % item + print + print " Total page count: %d" % self.total -cat <<EOF + def run(self): + for prefix, title in [ + ("api", "Python/C API"), + ("ext", "Extending and Embedding the Python Interpreter"), + ("lib", "Python Library Reference"), + ("mac", "Macintosh Module Reference"), + ("ref", "Python Reference Manual"), + ("tut", "Python Tutorial"), + ("doc", "Documenting Python"), + ]: + self.add_document(prefix, title) + print self.PREFIX + self.dump() + print self.SUFFIX + + PREFIX = """\ +This is the PostScript version of the standard Python documentation. +If you plan to print this, be aware that some of the documents are +long. The following manuals are included: +""" + SUFFIX = """\ If you have any questions, comments, or suggestions regarding these documents, please send them via email to python-docs@python.org. +""" + +def count_pages(filename): + fp = open(filename) + count = 0 + while 1: + lines = fp.readlines(1024*40) + if not lines: + break + for line in lines: + if line[:7] == "%%Page:": + count = count + 1 + fp.close() + return count + + +def main(): + PageCounter().run() -EOF +if __name__ == "__main__": + main() |