eriksmartt.com>Selected Archives

PyBlosxom install going a little more smoothly now

After a few more hours of hacking on it I think I've got PyBlosxom under control now. Being new to the tool I may have done a few things "wrong", but it made sense to me. First on the list was getting my RSS and Atom feeds working. From what I've read, the right way to do this might be using a special plugin for these formats, but that seemed overkill. Instead, I added an RSS and Atom 0.3 flavour, which makes defining the layout really easy. Unfortunately, there's a bit of code in the blosxom renderer that automatically encodes any content you declare as XML. I didn't want this, so I had to comment that stuff out. While in there, I also took out the built-in RSS flavour since I didn't want it conflicting with my own. To make sure it worked, I used the FEED Validator to check my feeds.

Next up was getting the ModRewrite stuff working. ModRewrite is voodoo, but fortunately I've done a bit of it in the past. I wanted to handle a couple things with ModRewrite. First was redirecting requests for my previously static-cached rss092.xml and atom.xml to the new dynamic feeds. The rules look something like this:

# Rewrite the static xml links instead of issuing a redirect
RewriteRule ^atom\.xml$ somewhere/index.cgi?flav=atom [last]
RewriteRule ^rss092\.xml$ somewhere/index.cgi?flav=rss [last]
RewriteRule ^blog/atom\.xml$ somewhere/index.cgi?flav=atom [last]
RewriteRule ^blog/rss092\.xml$ somewhere/index.cgi?flav=rss [last]

With that working, I went after hiding the 'index.cgi' bit when browsing. There were two situations to deal with: one when a page request comes in that actually HAS the index.cgi in it; and the second when it's missing. The two rules to do it look like this:

# Nuke the 'index.cgi' part if someone asked for it
RewriteRule ^blog/index.cgi(.*) somewhere/index.cgi$1 [last]

# Hide the index.cgi bit
RewriteRule ^blog/(.*) somewhere/index.cgi/$1 [last]

The second rule makes the first look redundant, but it's voodoo, and when all the above rules are put in the right order it works. All of these rules were defined in a .htaccess file in the root of the web documents directory. (You do have to turn the ReWrite engine on though, with the line: "RewriteEngine on".)

Next on the list was to block certain requests. I built a few other tools to run along side my PyBlosxom installation (which is in the "somewhere" path used above) but I wanted Authentication for some of the scripts. That was done with another .htaccess file that works sorta like this:

AuthType Basic
AuthName "Restricted Access"
AuthUserFile /home/myname/blog/.htpasswd
AuthGroupFile /home/myname/blog/.htgroups

<filesmatch "\.(py|pyc)$">
Require group admin
</filesmatch>

You can tweak the FilesMatch expression to match your specific needs.

About this time I was really wishing I wrote some test case scripts for the site to automate all the testing, but I didn't. Even something simple using the scrape module would have been handy. But instead of doing that, I decided to play a bit more with the plugin API and wrote two to test it out. The first is a super simple random sig plugin, found here: randomsig.py. I'm using it to pull a line for my header right now.

With the random sig working, I went on to a flickr plugin to pull my recent images into the sidebar. This was surprisingly easy, and the code is here: recentflickr.py. However, you'll notice that the script actually fetches recent images with EVERY page request. That's not really a good idea, so I've got a re-write in the works that caches images to a local directory.