#!/usr/bin/env python """Directory Index for Miscellanea.""" import cgitb; cgitb.enable() import sys, os, re, time from cgi import escape docroot = os.environ.get('DOCUMENT_ROOT', '.') sys.path.append(os.path.join(docroot, 'dev/code')) import inventory r_comment = re.compile(r"^[ \t]*#[^\r\n]*\r?\n") r_text = re.compile(r"[A-Za-z0-9\t\r\n :;,'_.-]+") r_whitespace = re.compile(r"[\t\r\n ]+") bufsize = 2048 def unescape(s): if not s: return s s = s.replace('<', '<') s = s.replace('>', '>') s = s.replace('&', '&') return s def getSummary(fn): try: f = open(fn) except: return None s = f.read(bufsize) f.close() s = r_comment.sub('', s) s = s.replace('\n', ' / ') text = ''.join(r_text.findall(s)) text = r_whitespace.sub(' ', text) if len(text) > 45: text = text[:45] + '&c.' return text metafile = {} if os.path.isfile('metafile.txt'): f = open('metafile.txt') for line in f: key, value = line.rstrip('\r\n').split(': ', 1) metafile[key] = value f.close() def makeTitle(fn): if metafile.has_key(fn): return metafile[fn] textext = ('.txt', '.py', '.cgi', '.rdf', '.c', '.php') if os.path.isfile(fn): for ext in textext: if fn.endswith(ext): title = escape(getSummary(fn)) break else: # title = inventory.title(fn) title = unescape(inventory.title(fn)) if title is not None: title = escape(title) elif os.path.isdir(fn): title = None fn += '/' else: title = None return title def main(): print "Content-Type: text/html; charset=utf-8" print """ Miscellanea

Miscellanea

Ephemeral Expoundings: Why?

Many people have directories that they use to public their random ephemera to the Web, and this is mine. The categories below are automatically generated.

Contentual Cataloguarity: What?

""" codext = frozenset(['.py']) svcext = frozenset(['.cgi']) docext = frozenset(['.html', '.txt']) imgext = frozenset(['.png', '.jpg']) cod, svc, doc, img, oth = [], [], [], [], [] inventory.options = inventory.Options(['basename', 'ignore', 'mtime']) inventory.options |= inventory.Options(['non-recursive', 'sitepath']) inventory.options |= inventory.Options(['strip', 'uniq']) for f in inventory.inventory(os.path.join(docroot, 'misc')): path, ext = os.path.splitext(f.relpath) if ext in codext: cod.append(f) elif ext in svcext: svc.append(f) elif ext in docext: doc.append(f) elif ext in imgext: img.append(f) else: oth.append(f) for files in (cod, svc, doc, img, oth): files.sort(lambda p, q: cmp(p.basename, q.basename)) li = '
  • %s%s - %s
  • ' print '

    Code

    ' print '' print '

    Services

    ' print '' print '

    Documentation

    ' print '' print '

    Images

    ' print '' print '

    Other

    ' print '' print """

    Pseudosemirandom Ponderings: How?

    CGI source of this page: /inside/misc. This directory follows the examples of Morbus' detergent and Aaron's 2002 in that it is a temporally independent warehouse of information (Aaron's directory name is a misleading misnomer). The name is based on Cody's similar choice of misc for d8uv.com.

    I like Morbus' description of his detergent section so much that I'm going to snarf it for here: "Welcome! Detergent[^Wmisc] is a grandiose collection of thingies cobbled together in an attempt to preserve the disorder I enjoy or else, have been a part of. Browse around, wonder fruitlessly about why I archived this or that, and do not have high expectations. It's random, esoteric, off-kilter, and smells. That's the point, bub."

    Sean B. Palmer, inamidst.com
    """ if __name__=="__main__": main()