Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Fred Drake | 47f6906 | 1998-08-28 21:16:28 +0000 | [diff] [blame] | 2 | |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 3 | """Generate a page count report of the PostScript version of the manuals.""" |
Fred Drake | 47f6906 | 1998-08-28 21:16:28 +0000 | [diff] [blame] | 4 | |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 5 | __version__ = '$Revision$' |
Fred Drake | 47f6906 | 1998-08-28 21:16:28 +0000 | [diff] [blame] | 6 | |
Fred Drake | bab5aa0 | 2002-04-17 03:29:40 +0000 | [diff] [blame^] | 7 | import getopt |
| 8 | import sys |
| 9 | |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 10 | |
| 11 | class PageCounter: |
| 12 | def __init__(self): |
| 13 | self.doclist = [] |
| 14 | self.total = 0 |
| 15 | self.title_width = 0 |
Fred Drake | bab5aa0 | 2002-04-17 03:29:40 +0000 | [diff] [blame^] | 16 | self.version = "" |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 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 | |
Fred Drake | bab5aa0 | 2002-04-17 03:29:40 +0000 | [diff] [blame^] | 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 | |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 38 | def run(self): |
Fred Drake | bab5aa0 | 2002-04-17 03:29:40 +0000 | [diff] [blame^] | 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) |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 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"), |
Greg Ward | 3abb104 | 2000-04-28 17:05:41 +0000 | [diff] [blame] | 52 | ("inst", "Installing Python Modules"), |
| 53 | ("dist", "Distributing Python Modules"), |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 54 | ]: |
| 55 | self.add_document(prefix, title) |
| 56 | print self.PREFIX |
| 57 | self.dump() |
| 58 | print self.SUFFIX |
| 59 | |
| 60 | PREFIX = """\ |
Fred Drake | 47f6906 | 1998-08-28 21:16:28 +0000 | [diff] [blame] | 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 |
Fred Drake | ba82878 | 2000-04-03 04:19:14 +0000 | [diff] [blame] | 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 |
Fred Drake | bab5aa0 | 2002-04-17 03:29:40 +0000 | [diff] [blame^] | 66 | Python reference material, consult the Python Bookstore at: |
Fred Drake | ba82878 | 2000-04-03 04:19:14 +0000 | [diff] [blame] | 67 | |
Fred Drake | bab5aa0 | 2002-04-17 03:29:40 +0000 | [diff] [blame^] | 68 | http://www.amk.ca/bookstore/ |
Fred Drake | ba82878 | 2000-04-03 04:19:14 +0000 | [diff] [blame] | 69 | |
Fred Drake | bab5aa0 | 2002-04-17 03:29:40 +0000 | [diff] [blame^] | 70 | The following manuals are included in this package: |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 71 | """ |
| 72 | SUFFIX = """\ |
Fred Drake | dfb4e24 | 1999-02-05 20:50:59 +0000 | [diff] [blame] | 73 | |
| 74 | |
| 75 | If you have any questions, comments, or suggestions regarding these |
| 76 | documents, please send them via email to python-docs@python.org. |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 77 | """ |
Fred Drake | dfb4e24 | 1999-02-05 20:50:59 +0000 | [diff] [blame] | 78 | |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 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() |