- Got rid of newmodule.c
[python/dscho.git] / Doc / tools / getpagecounts
blob202c73c47478c8c24dd1ef75060bf494972268cf
1 #! /usr/bin/env python
3 """Generate a page count report of the PostScript version of the manuals."""
5 __version__ = '$Revision$'
7 import getopt
8 import sys
11 class PageCounter:
12 def __init__(self):
13 self.doclist = []
14 self.total = 0
15 self.title_width = 0
16 self.version = ""
18 def add_document(self, prefix, title):
19 count = count_pages(prefix + ".ps")
20 self.doclist.append((title, prefix, count))
21 self.title_width = max(self.title_width, len(title))
22 self.total = self.total + count
24 def dump(self):
25 fmt = "%%-%ds (%%s.ps, %%d pages)" % self.title_width
26 for item in self.doclist:
27 print fmt % item
28 print
29 print " Total page count: %d" % self.total
31 def parse_options(self):
32 opts, args = getopt.getopt(sys.argv[1:], "r:", ["release="])
33 assert not args
34 for opt, arg in opts:
35 if opt in ("-r", "--release"):
36 self.version = arg
38 def run(self):
39 self.parse_options()
40 if self.version:
41 version = self.version[:3]
42 self.add_document("whatsnew" + version.replace(".", ""),
43 "What's New in Python " + version)
44 for prefix, title in [
45 ("api", "Python/C API"),
46 ("ext", "Extending and Embedding the Python Interpreter"),
47 ("lib", "Python Library Reference"),
48 ("mac", "Macintosh Module Reference"),
49 ("ref", "Python Reference Manual"),
50 ("tut", "Python Tutorial"),
51 ("doc", "Documenting Python"),
52 ("inst", "Installing Python Modules"),
53 ("dist", "Distributing Python Modules"),
55 self.add_document(prefix, title)
56 print self.PREFIX
57 self.dump()
58 print self.SUFFIX
60 PREFIX = """\
61 This is the PostScript version of the standard Python documentation.
62 If you plan to print this, be aware that some of the documents are
63 long. It is formatted for printing on two-sided paper; if you do plan
64 to print this, *please* print two-sided if you have a printer capable
65 of it! To locate published copies of the larger manuals, or other
66 Python reference material, consult the Python Bookstore at:
68 http://www.amk.ca/bookstore/
70 The following manuals are included in this package:
71 """
72 SUFFIX = """\
75 If you have any questions, comments, or suggestions regarding these
76 documents, please send them via email to python-docs@python.org.
77 """
79 def count_pages(filename):
80 fp = open(filename)
81 count = 0
82 while 1:
83 lines = fp.readlines(1024*40)
84 if not lines:
85 break
86 for line in lines:
87 if line[:7] == "%%Page:":
88 count = count + 1
89 fp.close()
90 return count
93 def main():
94 PageCounter().run()
96 if __name__ == "__main__":
97 main()