blob: 202c73c47478c8c24dd1ef75060bf494972268cf [file] [log] [blame]
Fred Drake46ab6df1999-08-03 17:54:39 +00001#! /usr/bin/env python
Fred Drake47f69061998-08-28 21:16:28 +00002
Fred Drake46ab6df1999-08-03 17:54:39 +00003"""Generate a page count report of the PostScript version of the manuals."""
Fred Drake47f69061998-08-28 21:16:28 +00004
Fred Drake46ab6df1999-08-03 17:54:39 +00005__version__ = '$Revision$'
Fred Drake47f69061998-08-28 21:16:28 +00006
Fred Drakebab5aa02002-04-17 03:29:40 +00007import getopt
8import sys
9
Fred Drake46ab6df1999-08-03 17:54:39 +000010
11class PageCounter:
12 def __init__(self):
13 self.doclist = []
14 self.total = 0
15 self.title_width = 0
Fred Drakebab5aa02002-04-17 03:29:40 +000016 self.version = ""
Fred Drake46ab6df1999-08-03 17:54:39 +000017
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
23
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
30
Fred Drakebab5aa02002-04-17 03:29:40 +000031 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
37
Fred Drake46ab6df1999-08-03 17:54:39 +000038 def run(self):
Fred Drakebab5aa02002-04-17 03:29:40 +000039 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)
Fred Drake46ab6df1999-08-03 17:54:39 +000044 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"),
Greg Ward3abb1042000-04-28 17:05:41 +000052 ("inst", "Installing Python Modules"),
53 ("dist", "Distributing Python Modules"),
Fred Drake46ab6df1999-08-03 17:54:39 +000054 ]:
55 self.add_document(prefix, title)
56 print self.PREFIX
57 self.dump()
58 print self.SUFFIX
59
60 PREFIX = """\
Fred Drake47f69061998-08-28 21:16:28 +000061This is the PostScript version of the standard Python documentation.
62If you plan to print this, be aware that some of the documents are
Fred Drakeba828782000-04-03 04:19:14 +000063long. It is formatted for printing on two-sided paper; if you do plan
64to print this, *please* print two-sided if you have a printer capable
65of it! To locate published copies of the larger manuals, or other
Fred Drakebab5aa02002-04-17 03:29:40 +000066Python reference material, consult the Python Bookstore at:
Fred Drakeba828782000-04-03 04:19:14 +000067
Fred Drakebab5aa02002-04-17 03:29:40 +000068 http://www.amk.ca/bookstore/
Fred Drakeba828782000-04-03 04:19:14 +000069
Fred Drakebab5aa02002-04-17 03:29:40 +000070The following manuals are included in this package:
Fred Drake46ab6df1999-08-03 17:54:39 +000071"""
72 SUFFIX = """\
Fred Drakedfb4e241999-02-05 20:50:59 +000073
74
75If you have any questions, comments, or suggestions regarding these
76documents, please send them via email to python-docs@python.org.
Fred Drake46ab6df1999-08-03 17:54:39 +000077"""
Fred Drakedfb4e241999-02-05 20:50:59 +000078
Fred Drake46ab6df1999-08-03 17:54:39 +000079def 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
91
92
93def main():
94 PageCounter().run()
95
96if __name__ == "__main__":
97 main()