|
| 1 | +#! /usr/bin/env python |
| 2 | +# |
| 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. |
| 6 | +# |
| 7 | +# The output of this script can be pasted directly into the download |
| 8 | +# page for the documentation. |
| 9 | + |
| 10 | +import os |
| 11 | +import sys |
| 12 | + |
| 13 | +from os.path import isfile |
| 14 | + |
| 15 | + |
| 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"), |
| 26 | + ] |
| 27 | + |
| 28 | + |
| 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) |
| 39 | + |
| 40 | +print '''\ |
| 41 | +<table border="1" cellpadding="3" align="center"> |
| 42 | + <thead> |
| 43 | + <tr bgcolor="#3399ff"><th rowspan="2">Content</th> |
| 44 | + <th colspan="3">Format</th> |
| 45 | + </tr> |
| 46 | + <tr bgcolor="#3399ff"><th>ZIP</th><th>GZip</th><th>BZip2</th> |
| 47 | + </thead> |
| 48 | + <tbody>''' |
| 49 | + |
| 50 | +# formatted using FILE_TEMPLATE % (release, prefix, release, extension) |
| 51 | +FILE_TEMPLATE = '''\ |
| 52 | + <td><a href="../../ftp/python/doc/%s/%s-%s%s" |
| 53 | + >%dK</a></td>''' |
| 54 | + |
| 55 | +NO_FILE_TEMPLATE = '''\ |
| 56 | + <td> </td>''' |
| 57 | + |
| 58 | +def get_size(prefix, ext): |
| 59 | + fn = "%s-%s%s" % (prefix, release, ext) |
| 60 | + return int(round(os.path.getsize(fn) / 1024.0)) |
| 61 | + |
| 62 | +for name, prefix in PKG_TYPES: |
| 63 | + zip_fn = "%s-%s.zip" % (prefix, release) |
| 64 | + tgz_fn = "%s-%s.tgz" % (prefix, release) |
| 65 | + bz2_fn = "%s-%s.tar.bz2" % (prefix, release) |
| 66 | + |
| 67 | + have_zip = isfile(zip_fn) |
| 68 | + have_tgz = isfile(tgz_fn) |
| 69 | + have_bz2 = isfile(bz2_fn) |
| 70 | + |
| 71 | + if have_zip or have_tgz or have_bz2: |
| 72 | + print " <tr><td>%s</td>" % name |
| 73 | + |
| 74 | + if have_zip: |
| 75 | + kb = get_size(prefix, ".zip") |
| 76 | + print FILE_TEMPLATE % (release, prefix, release, ".zip", kb) |
| 77 | + else: |
| 78 | + print NO_FILE_TEMPLATE |
| 79 | + |
| 80 | + if have_tgz: |
| 81 | + kb = get_size(prefix, ".tgz") |
| 82 | + print FILE_TEMPLATE % (release, prefix, release, ".tgz", kb) |
| 83 | + else: |
| 84 | + print NO_FILE_TEMPLATE |
| 85 | + |
| 86 | + if have_bz2: |
| 87 | + kb = get_size(prefix, ".tar.bz2") |
| 88 | + print FILE_TEMPLATE % (release, prefix, release, ".tar.bz2", kb) |
| 89 | + else: |
| 90 | + print NO_FILE_TEMPLATE |
| 91 | + |
| 92 | + print " </tr>" |
| 93 | + |
| 94 | +print '''\ |
| 95 | + </tbody> |
| 96 | +</table> |
| 97 | +''' |
0 commit comments