/stuff/updates.cgi

#!/usr/bin/env python
"""
Site Updates - Show the updates for inamidst.com
License: GPL 2; share and enjoy!
Author: Sean B. Palmer, inamidst.com
"""

head = """\
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Recent Updates to inamidst.com</title>
<link rel="stylesheet" type="text/css" href="/trove/simple.css" />
<link rel="stylesheet" type="text/css" href="/trove/pwyky.css" />
<style type="text/css">
li.change { list-style-image: url(/trove/pointer); }
</style>
</head>
<body>
<div class="nav">
<a href="/"><img src="/trove/logo" alt="inamidst.com" /></a>
</div>
<h1>Recent Updates</h1>

<p>This is a list of the most recently modified files on the site, with all
times in UTC. See also the improved <a href="/changes/">Changes and Updates</a>
service which displays updates to the site based on changesets rather than file
modification times, and provides diffs for each change so you can find out
exactly which lines have changed in the files.</p>
"""

tail = """\
<p>Source: <a href="/inside/updates">Python CGI</a>.</p>
<address>
<a href="http://inadmist.com/sbp/">Sean B. Palmer</a>
</address>
</body>
</html>
"""

import cgitb; cgitb.enable()
import sys, os 
docroot = os.environ.get('DOCUMENT_ROOT', '.')
sys.path.extend((
   os.path.join(docroot, 'changes'), 
   os.path.join(docroot, 'dev/code')
))

import changes, inventory

def getUpdates(): 
   for (day, time, link) in inventory.genupdates(): 
      yield (day, time, '<a href="%s">%s</a>' % (link, link), 'update')

def getChanges(): 
   for (day, time, message) in changes.genchanges(): 
      link = '<a href="#T%s">%s</a>' % (day, message)
      yield (day, time, link, 'change')

def changesAndUpdates(): 
   import itertools
   g = itertools.chain(getUpdates(), getChanges())
   for thing in reversed(sorted(g)): 
      yield thing

def main(): 
   doc = __doc__[__doc__.find('---')+3:]
   print 'Content-Type: text/html'
   print 
   print head

   pday = None
   for (day, time, html, cls) in changesAndUpdates(): 
      if day != pday: 
         if pday is not None: 
            print '</ul>'
            print 
         pday = day

         print '<h2 id="T%s">%s</h2>' % (day, day)
         print '<ul>'
      print '<li class="%s">%s (%s)</li>' % (cls, html, time)
   print '</ul>'

   print tail

if __name__=="__main__": 
   main()