1 | #! /usr/bin/env python
|
---|
2 |
|
---|
3 | """Generate a page count report of the PostScript version of the manuals."""
|
---|
4 |
|
---|
5 | __version__ = '$Revision: 39598 $'
|
---|
6 |
|
---|
7 | import getopt
|
---|
8 | import sys
|
---|
9 |
|
---|
10 |
|
---|
11 | class PageCounter:
|
---|
12 | def __init__(self):
|
---|
13 | self.doclist = []
|
---|
14 | self.total = 0
|
---|
15 | self.title_width = 0
|
---|
16 | self.version = ""
|
---|
17 |
|
---|
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 |
|
---|
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
|
---|
37 |
|
---|
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"),
|
---|
54 | ]:
|
---|
55 | self.add_document(prefix, title)
|
---|
56 | print self.PREFIX
|
---|
57 | self.dump()
|
---|
58 | print self.SUFFIX
|
---|
59 |
|
---|
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:
|
---|
67 |
|
---|
68 | http://wiki.python.org/moin/PythonBooks
|
---|
69 |
|
---|
70 | The following manuals are included in this package:
|
---|
71 | """
|
---|
72 | SUFFIX = """\
|
---|
73 |
|
---|
74 |
|
---|
75 | If you have any questions, comments, or suggestions regarding these
|
---|
76 | documents, please send them via email to docs@python.org.
|
---|
77 | """
|
---|
78 |
|
---|
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
|
---|
91 |
|
---|
92 |
|
---|
93 | def main():
|
---|
94 | PageCounter().run()
|
---|
95 |
|
---|
96 | if __name__ == "__main__":
|
---|
97 | main()
|
---|