BlogMatrix
 

Internals: bash 3.1 chokes mod_python 3.2.8

edit David P. Janes 2006-08-25 20:05 UTC add comment  ·  ·

I was rebuilding the BlogMatrix Platform on a Fedora Core 5 box this morning when I noticed mod_python wasn't being properly set up. The issue turns out to be that mod_python fails to build:

./configure: line 3427: syntax error near unexpected token `('
./configure: line 3427: `  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`'
+ exit 1

Through the magic of Google, we quickly found a fix:

A bug in bash 3.1 causes configure to fail. This has been reported on recent versions of Gentoo and and discussed on the mod_python mailing list:
http://bugs.gentoo.org/show_bug.cgi?id=118948
http://www.modpython.org/pipermail/mod_python/2006-January/019965.html
http://www.modpython.org/pipermail/mod_python/2006-January/019969.html

According to the gentoo bug report, the problem in configure.in is the double backslash escape sequence in the line:
MP_VERSION=`echo $MP_VERSION | sed s/\\"//g`

Changing this to:
MP_VERSION=`echo $MP_VERSION | sed s/\"//g`
fixes it for bash 3.1.

I wonder why mod_python is using \\" since the gentoo fix seems to work ok with bash 3.0 (and GNU sed) just as well. Is it there to support other shells, other sed versions, older bash versions... ??

I suggest mod_python adopts the gentoo fix, or avoids the problem altogether by using tr. eg.

MP_VERSION=`echo $MP_VERSION | tr -d '"'` 

Internals: tracking all actions against a page view

edit David P. Janes 2006-08-02 12:40 UTC add comment  ·  ·  ·

One of the nice things -- that took me a while to realize -- is that you're working in a single treaded environment in mod_python. One that's getting reused over and over and over, but while you got it you got it.

I've added an extension to bm_log to allow tracking of all logging related to creating a page. You use it as follows:

  • call Log.PageStart
  • do stuff
  • call Log.PageEnd

In fact, you don't even need to do this, since PageStart and PageEnd are always called in bm_page in the right places, so all you're responsible for is the "do stuff" part.

Now what does this do? Simple:

  • PageStart assigns a unique (random) id the logging function and records the start time
  • all subsequent calls to Log print the random id and the delta from the start time
  • PageEnd clears the unique id
 

Internals: Using mod_rewrite to let BlogMatrix serve hostnames

edit David P. Janes 2006-07-23 11:13 UTC add comment  ·

One thing I'm planning to do in the very near future is to move my weblog AND my del.icio.us links all over to (semantic.)blogmatrix.com. This will give me a weblog with 5000+ entries and lots of comments to test the edges of our code. I've already offered a bounty to help us write a MovableType converter, though it looks like I'll have to finish writing this myself.

Here's the changes (in bold) I had to make to our primary server's httpd.conf to make this work:

<VirtualHost *:80>
 ServerAlias *.semantic.blogmatrix.com
 ServerAlias weblog.davidjanes.com

 # special rules for users with their own blog name
 RewriteCond %{HTTP_HOST}   ^weblog.davidjanes.com$
 RewriteRule ^.*$           @davidjanes.semantic.blogmatrix.com$0


 # host based rewriting
 RewriteRule ^[@](.+)       $1 [S=1]
 RewriteRule ^.+            %{HTTP_HOST}$0
</VirtualHost>

Notes:

  • "[S=1]" means skip the next line; if we're rewriting for a user host we don't need the standard rule that inserts the username.semantic.blogmatrix.com into the rules
  • We'd just repeat the "# special rules" section as many times as we needed. The RewriteCond only applies to the next line
  • We'll need some way of making this very dynamic so user's can just set up the hostname without operator intervention

There's going to need to be more recognition of the user's preferred host name in the code, but I'll work on this later.

Internals: Apache rewrite rules for Python attachments

edit David P. Janes 2006-07-18 10:55 UTC add comment  ·  ·

We were having a problem with serving .py files as attachments this morning. It turns out the problem was in the primary rewrite rules so I've made this rule:

RewriteRule   ^([^.]+)\.[^/]+/+(\d\d\d\d/\d\d\.\d\d/\d\d\d\d+/+.*)  http://semantic.blogmatrix.com/users/$1/podcasts/$2  

The first in it's group, that is, we'll attempt to serve attachments (recognized by all the \ds) before we look for .py files (in which URIs are normally passed straight through for mod_python handling by the secondary Apache).