#!/usr/bin/env python # read index data out of a table and present it as a web page import sys,os,md5 sys.path.append('/home/acb/null_include') from stat import * from Comments import Comments DATASRC='INDEX.data' FILE_DIR='/www/null.org/htdocs/audio/_files' DL_CGI='/cgi-bin/servemp3' CMT_DBNAME='null' CMT_DBUSER='acb' CMT_BASEURL="/cgi-bin/comment.cgi" CMT_GROUP='mp3' cmts = Comments(CMT_DBNAME, user=CMT_DBUSER, cmtbaseurl=CMT_BASEURL, group=CMT_GROUP) # the data file consists of one-line Name:Value pairs, separated by blank lines # Records consisting of a sole Heading: line are section headings. # the # character begins a one-line comment def readRecord(file,defaults={}): "Read a record and return as a dict, or None if none remaining" result = {} l = file.readline() # skip any initial blank lines while l=='\n': l = file.readline() if l=='': return None while len(l)>1: if l[0]=='#': l = file.readline() continue (k,v) = map(lambda s:s.strip(),(l.split(':',1)+[None])[:2]) if k: result[k.lower()]=v l = file.readline() for k in defaults.keys(): if not result.has_key(k): result[k]=defaults[k] return result def emitHeading(hdg): print "
%(title)s"""%dict, if dict.has_key('year'): print '(%s)'%dict['year'] print '
' if dict.has_key('description'): print '%s
'%dict['description'] if dict.has_key('reviews'): print '%s
'%dict['reviews'] if dict.has_key('credits'): print '%s
'%dict['credits'] if dict.has_key('file'): fname = dict['file'] try: stat = os.stat("%s/%s"%(FILE_DIR,fname)) if stat[ST_SIZE]>=900*1024: fsize = "%.1fMb"%(stat[ST_SIZE]/1048576.0) else: fsize = "%dk"%(stat[ST_SIZE]/1024) except OSError: fname, fsize = None, None if fname: print '[Download %s %s]'%(DL_CGI,fname,fsize,dict['type']) if cmt_item: cmt_url = "%s?it=%s&mc=%s&gr=%s"%(CMT_BASEURL,cmt_item,cmts.mkmc(cmt_item),CMT_GROUP) if num_cmts == 0: print '[no comments]'%cmt_url elif num_cmts == 1: print '[1 comment]'%cmt_url else: try: print '[%d comments]'%(cmt_url,num_cmts) except TypeError: pass print "© acb 2003. If you can read this, the page has loaded.
"""