If you run a pyblosxom blog with auto-copied stories from SVN you are probably interested in getting stable story dates that don't change every time you update a story. The date of the initial SVN log entry of a story is something like the "day of birth" of a story, so it's a good value to use. Christopher Baus implemented a plugin for pyblosxom, which looks overly complicated to me: it depends on memcached and comes in two large python scripts.
To simplify things I wrote this minimal replacement:
import pysvn, os, sys, anydbm
from config import py
def get_mtime(fname):
cache_fname = os.path.join(py['datadir'], 'SVNDATES')
cache = anydbm.open(cache_fname, "c")
if cache.has_key(fname):
d = float(cache[fname])
else:
client = pysvn.Client(fname)
l = client.log(fname)
if len(l) > 0:
d = l[0]['date']
cache[fname] = str(d)
else:
d = -1
del client
del cache
return d
def cb_filestat(args):
args["mtime"] = list(args["mtime"])
d = get_mtime(args["filename"])
if d >= 0:
args["mtime"][8] = d
return args
Since accessing SVN logs is quite slow the script caches the "date of birth" in a dbm file. Make sure that your web server has enough priviliges to access that database file which is stored in $datadir/SVNDATES by default.
posted at: 15:57 | path: /projects | permanent link to this entry | 0 comments
It should be obvious but in case it isn't: the opinions reflected here are my own. They are not the views of my employer, or Ronald McDonald, or anyone else.
Please note that I take the liberty to delete any comments posted here that I deem inappropriate, off-topic, or insulting. And I excercise this liberty quite agressively. So yes, if you comment here, I might censor you. If you don't want to be censored your are welcome to comment on your own blog instead.