#!/usr/local/bin/python1.5 # -*- python -*- import httplib, sys, time, os, re, string, stat libsource = '/doc/lib/lib.html' tocfile = os.path.expanduser('~skip/public_html/python/libtoc.html') def get_lib_toc(): if os.path.exists(tocfile): timestamp = os.stat(tocfile)[stat.ST_MTIME] else: timestamp = 0 httpobj = httplib.HTTP('www.python.org', 80) httpobj.putrequest('GET', libsource) httpobj.putheader('If-Modified-Since', time.strftime('%a, %d %b %Y %X GMT', time.localtime(timestamp))) httpobj.putheader('Accept', 'text/html') httpobj.endheaders() reply, msg, hdrs = httpobj.getreply() if reply == 200: return httpobj.getfile().readlines() else: return [] def compare(s,t): s = string.lower(s[0][0]) t = string.lower(t[0][0]) if s < t: return -1 if s > t: return 1 return 0 def main(): mpat = re.compile(' *HREF="([^"]*)">' ']*>[0-9]+\.]*>[0-9]+' ' +([^<]*) --', re.I) lines = get_lib_toc() if lines: modules = [] for line in lines: m = mpat.match(string.strip(line)) if m is not None: modules.append(map(string.strip, map(m.group, [2, 1]))) if not modules: print "Error! No lines in the library manual matched!" return out = open(tocfile, 'w') out.write(""" Python Library Module Quick Reference

Python v1.5 Library Module Quick Reference

Extracted from the Python Library Reference Manual.

Updated: %s

""" % (libsource, time.strftime('%a, %d %b %Y %X GMT', time.localtime(time.time())))) modules.sort(compare) ldict = {} for ent in modules: # make key lower case so _ sorts ahead of letters later on first = string.lower(ent[0][0]) try: ldict[first].append(ent) except KeyError: ldict[first] = [ent] # split into two groups, one set for the first column and one # for the right # this is very crude - but my brain is a little fried from lack # of sleep, so I'm doing it the brute force way half = len(ldict)/2+len(ldict)%2 keys = ldict.keys() keys.sort() left = keys[:half] right = keys[half:] ncols = 3 for i in range(len(left)): out.write("\n") # left hand column letter = ldict[left[i]] out.write("
%s\n" % string.upper(left[i])) out.write("\n") out.write("\n") col = 0 for ent in letter: if col == 0: out.write("\n") col = (col + 1) % ncols out.write('\n' % (ent[1], ent[0])) out.write("
%s
\n") # try to emit a right-hand column try: letter = ldict[right[i]] out.write("
%s\n" % string.upper(right[i])) out.write("\n") out.write("\n") col = 0 for ent in letter: if col == 0: out.write("\n") col = (col + 1) % ncols out.write('\n' % (ent[1], ent[0])) out.write("
%s
\n") except IndexError: out.write("
 \n") out.write("""

Last Modified: %s """ % (time.strftime('%a, %d %b %Y %X GMT', time.localtime(time.time())))) if __name__ == '__main__': main()