~exarkun/pyopenssl/trunk

« back to all changes in this revision

Viewing changes to doc/tools/getpagecounts

  • Committer: Jean-Paul Calderone
  • Date: 2011-09-11 19:49:43 UTC
  • mfrom: (156.3.22 sphinx-doc)
  • Revision ID: exarkun@divmod.com-20110911194943-ucaan2tzidk7ek5l
Convert the documentation from LaTeX/epytext to Sphinx/ReST

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
 
#  -*- Python -*-
3
 
 
4
 
"""Generate a page count report of the PostScript version of the manuals."""
5
 
 
6
 
__version__ = '$Revision: 1.1.1.1 $'
7
 
 
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
 
            ("inst", "Installing Python Modules"),
38
 
            ("dist", "Distributing Python Modules"),
39
 
            ]:
40
 
            self.add_document(prefix, title)
41
 
        print self.PREFIX
42
 
        self.dump()
43
 
        print self.SUFFIX
44
 
 
45
 
    PREFIX = """\
46
 
This is the PostScript version of the standard Python documentation.
47
 
If you plan to print this, be aware that some of the documents are
48
 
long.  It is formatted for printing on two-sided paper; if you do plan
49
 
to print this, *please* print two-sided if you have a printer capable
50
 
of it!  To locate published copies of the larger manuals, or other
51
 
Python reference material, consult the PSA Online Bookstore at:
52
 
 
53
 
             http://www.python.org/psa/bookstore/
54
 
 
55
 
The following manuals are included:
56
 
"""
57
 
    SUFFIX = """\
58
 
 
59
 
 
60
 
If you have any questions, comments, or suggestions regarding these
61
 
documents, please send them via email to python-docs@python.org.
62
 
 
63
 
If you would like to support the development and maintenance of
64
 
documentation for Python, please consider joining the Python Software
65
 
Activity (PSA; see http://www.python.org/psa/), or urging your
66
 
organization to join the PSA or the Python Consortium (see
67
 
http://www.python.org/consortium/).
68
 
"""
69
 
 
70
 
def count_pages(filename):
71
 
    fp = open(filename)
72
 
    count = 0
73
 
    while 1:
74
 
        lines = fp.readlines(1024*40)
75
 
        if not lines:
76
 
            break
77
 
        for line in lines:
78
 
            if line[:7] == "%%Page:":
79
 
                count = count + 1
80
 
    fp.close()
81
 
    return count
82
 
 
83
 
 
84
 
def main():
85
 
    PageCounter().run()
86
 
 
87
 
if __name__ == "__main__":
88
 
    main()