Maintain backwards compatibility with python < 2.3 by dynamically
[python/dscho.git] / Doc / tools / mkpkglist
blob0dd391624278f8eadbbe8cd93aca3fab6ce508f5
1 #! /usr/bin/env python
3 # Simple script to create the table that lists the packages available
4 # for download. This expects the downloadable files and the Makefile
5 # to be in the current directory.
7 # The output of this script can be pasted directly into the download
8 # page for the documentation.
10 import os
11 import sys
13 from os.path import isfile
16 PKG_TYPES = [
17 # human name, filename prefix
18 ("HTML", "html"),
19 ("PDF (US-Letter)", "pdf-letter"),
20 ("PDF (A4)", "pdf-a4"),
21 ("PostScript (US-Letter)", "postscript-letter"),
22 ("PostScript (A4)", "postscript-a4"),
23 ("GNU info", "info"),
24 ("iSilo", "isilo"),
25 ("LaTeX", "latex"),
29 fp = open("Makefile")
30 for line in fp:
31 line = line.replace('=', ' ', 1)
32 parts = line.split()
33 if parts[:1] == ["RELEASE"]:
34 release = parts[1]
35 break
36 else:
37 print >>sys.stderr, "Could not locate RELEASE in Makefile."
38 sys.exit(1)
40 print '''\
41 <table border="1" cellpadding="3" align="center">
42 <thead>
43 <tr bgcolor="#99ccff"><th rowspan="2">Content</th>
44 <th colspan="3">Format</th></tr>
45 <tr bgcolor="#99ccff"><th>ZIP</th><th>GZip</th><th>BZip2</th></tr>
46 </thead>
47 <tbody>'''
49 # formatted using FILE_TEMPLATE % (release, prefix, release, extension)
50 FILE_TEMPLATE = '''\
51 <td><a href="../../ftp/python/doc/%s/%s-%s%s"
52 >%dK</a></td>'''
54 NO_FILE_TEMPLATE = '''\
55 <td>&nbsp;</td>'''
57 def get_size(prefix, ext):
58 fn = "%s-%s%s" % (prefix, release, ext)
59 return int(round(os.path.getsize(fn) / 1024.0))
61 def get_file_cell(prefix, ext, have):
62 if have:
63 kb = get_size(prefix, ext)
64 return FILE_TEMPLATE % (release, prefix, release, ext, kb)
65 else:
66 return NO_FILE_TEMPLATE
68 for name, prefix in PKG_TYPES:
69 zip_fn = "%s-%s.zip" % (prefix, release)
70 tgz_fn = "%s-%s.tgz" % (prefix, release)
71 bz2_fn = "%s-%s.tar.bz2" % (prefix, release)
73 have_zip = isfile(zip_fn)
74 have_tgz = isfile(tgz_fn)
75 have_bz2 = isfile(bz2_fn)
77 if have_zip or have_tgz or have_bz2:
78 print " <tr><td>%s</td>" % name
80 print get_file_cell(prefix, ".zip", have_zip)
81 print get_file_cell(prefix, ".tgz", have_tgz)
82 print get_file_cell(prefix, ".tar.bz2", have_bz2)
84 print " </tr>"
86 print '''\
87 </tbody>
88 </table>
89 '''