Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | # -*- Python -*- |
Fred Drake | 47f6906 | 1998-08-28 21:16:28 +0000 | [diff] [blame] | 3 | |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 4 | """Generate a page count report of the PostScript version of the manuals.""" |
Fred Drake | 47f6906 | 1998-08-28 21:16:28 +0000 | [diff] [blame] | 5 | |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 6 | __version__ = '$Revision$' |
Fred Drake | 47f6906 | 1998-08-28 21:16:28 +0000 | [diff] [blame] | 7 | |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 8 | |
| 9 | class PageCounter: |
| 10 | def __init__(self): |
| 11 | self.doclist = [] |
| 12 | self.total = 0 |
| 13 | self.title_width = 0 |
| 14 | |
| 15 | def add_document(self, prefix, title): |
| 16 | count = count_pages(prefix + ".ps") |
| 17 | self.doclist.append((title, prefix, count)) |
| 18 | self.title_width = max(self.title_width, len(title)) |
| 19 | self.total = self.total + count |
| 20 | |
| 21 | def dump(self): |
| 22 | fmt = "%%-%ds (%%s.ps, %%d pages)" % self.title_width |
| 23 | for item in self.doclist: |
| 24 | print fmt % item |
| 25 | print |
| 26 | print " Total page count: %d" % self.total |
| 27 | |
| 28 | def run(self): |
| 29 | for prefix, title in [ |
| 30 | ("api", "Python/C API"), |
| 31 | ("ext", "Extending and Embedding the Python Interpreter"), |
| 32 | ("lib", "Python Library Reference"), |
| 33 | ("mac", "Macintosh Module Reference"), |
| 34 | ("ref", "Python Reference Manual"), |
| 35 | ("tut", "Python Tutorial"), |
| 36 | ("doc", "Documenting Python"), |
| 37 | ]: |
| 38 | self.add_document(prefix, title) |
| 39 | print self.PREFIX |
| 40 | self.dump() |
| 41 | print self.SUFFIX |
| 42 | |
| 43 | PREFIX = """\ |
Fred Drake | 47f6906 | 1998-08-28 21:16:28 +0000 | [diff] [blame] | 44 | This is the PostScript version of the standard Python documentation. |
| 45 | 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] | 46 | long. It is formatted for printing on two-sided paper; if you do plan |
| 47 | to print this, *please* print two-sided if you have a printer capable |
| 48 | of it! To locate published copies of the larger manuals, or other |
| 49 | Python reference material, consult the PSA Online Bookstore at: |
| 50 | |
| 51 | http://www.python.org/psa/bookstore/ |
| 52 | |
| 53 | The following manuals are included: |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 54 | """ |
| 55 | SUFFIX = """\ |
Fred Drake | dfb4e24 | 1999-02-05 20:50:59 +0000 | [diff] [blame] | 56 | |
| 57 | |
| 58 | If you have any questions, comments, or suggestions regarding these |
| 59 | documents, please send them via email to python-docs@python.org. |
Fred Drake | ba82878 | 2000-04-03 04:19:14 +0000 | [diff] [blame] | 60 | |
| 61 | If you would like to support the development and maintenance of |
| 62 | documentation for Python, please consider joining the Python Software |
| 63 | Activity (PSA; see http://www.python.org/psa/), or urging your |
| 64 | organization to join the PSA or the Python Consortium (see |
| 65 | http://www.python.org/consortium/). |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 66 | """ |
Fred Drake | dfb4e24 | 1999-02-05 20:50:59 +0000 | [diff] [blame] | 67 | |
Fred Drake | 46ab6df | 1999-08-03 17:54:39 +0000 | [diff] [blame] | 68 | def count_pages(filename): |
| 69 | fp = open(filename) |
| 70 | count = 0 |
| 71 | while 1: |
| 72 | lines = fp.readlines(1024*40) |
| 73 | if not lines: |
| 74 | break |
| 75 | for line in lines: |
| 76 | if line[:7] == "%%Page:": |
| 77 | count = count + 1 |
| 78 | fp.close() |
| 79 | return count |
| 80 | |
| 81 | |
| 82 | def main(): |
| 83 | PageCounter().run() |
| 84 | |
| 85 | if __name__ == "__main__": |
| 86 | main() |