A slightly lest peddestrian code is available in the nipy.modalities.fmri.glm.py
See e.g. examples/labs/need_data/first_level_fiac.py