Added locking to Pyblosxom

Note: This is an old post in a blog with a lot of posts over a long span of time. The world has changed, technologies have changed, and I've changed. It's likely this is out of date, the code doesn't work, the ideas haven't aged well, or the ideas were terrible to begin with. Let me know if you think this is something that needs updating.

I just added locking to Pyblosxom to allow separate Pyblosxom requests to synchronize on centralized data. In my case, the data is a file of how many views each of my blog entries has gotten. It seems to be pretty functional. It's something I had coded in my viewcounts plugin, but I've moved the code (and added to it) into the tools module so we can all use the same base.

An example of usage is this:

from Pyblosxom import tools

LOCKNAME = "viewcounts.dat"

lockret = tools.get_lock(request, LOCKNAME)
if lockret:
    # yay -- we have the lcok
    pass
else:
    # foo -- we don't have the lock
    pass


if tools.has_lock(request, LOCKNAME)
    # yay -- we have the lock
    pass
else:
    # foo -- we don't have the lock
    pass

tools.return_lock(request, LOCKNAME)

The code is in CVS. It'll go into the next version. Also, I added a unittest module to the code base.

Want to comment? Send an email to willkg at bluesock dot org. Include the url for the blog entry in your comment so I have some context as to what you're talking about.