Archive for the 'Scripting' Category

Compiling PHP 5.2.11 on OS X 10.5.8

I’ve detailed this problem before but yet again I’ve encountered the infamous iconv compile error. This bug is not new yet it still has not been fixed in the latest PHP release.

When compiling a custom version of PHP with libraries such as libxml and iconv the make process results in a linking error relating to the iconv library. The problem arises because I have two versions of iconv installed – the macports version in addition to the standard installation. A linking conflict arises and to eliminate the error a linking search order change (which is detailed in my previous blog post) must be made. In addition to the makefile modification, the previous workaround for the bug also included using --with-iconv=shared,/opt/local instead of the standard --with-iconv. Either the latest PHP (5.2.11) or OS X update has caused that workaround not to function correctly, now only --with-iconv=/opt/local should be used.

I’ve posted a script that I’m now using to keep my PHP installation up to date.

Subversion Post Commit & DreamHost Hosting

I use a combination of Trac and Subversion to manage my software development projects. Although new projects like lighthouse and git have cropped up which look very intriguing, the lack of automated installation and maintaince and my lack of free time leaves my turning back to my existing trac + svn solution. The integration between these two projects is simply spectacular and the ability to have the software hosted and easily managed on a low cost shared server like DreamHost is definitely a plus.

There was one missing piece after the initial installation process of svn + trac: post commit trac integration. Automatic integration of ticket updates and source code commits usually runs without a problem, but since svn runs under a different user than trac, permission issues arise. The easy solution would be to increase permissions on the trac database file, but this isn’t a very secure solution. The best solution that I have found is to create a proxy file, which holds basic commit information (revision numbers and commit messages), to act as a middleman between trac and svn and then schedule a cron script to pull the logged data and run it through the trac post commit script. Information on how to do this was scattered around the web so I took the time to pull it all together and organize it into one post.

File: ~/trac_projects/project_name/run-post-commit-proxy.bash
Note that this file needs to be run by the same user which handles svn commits (on DreamHost just run this script every five minutes as the user which hosts your svn).

#!/bin/bash

LD_LIBRARY_PATH="/home/user/packages/lib"
PATH="/home/user/packages/bin:$PATH"
PYTHONPATH="/home/user/packages/lib/python2.4/site-packages"

export PYTHONPATH
export PATH
export LD_LIBRARY_PATH

/home/user/trac_projects/project_name/run-queued-trac-post-commits.rb

File: ~/trac_projects/project_name/run-queued-trac-post-commits.rb

#!/usr/bin/ruby

tracDir = '/home/user/trac_projects/project_name'
logFilePath = tracDir + '/queued_commits.txt'
doneFilePath = tracDir + '/queued_post_commits_done.txt'
errorFilePath = tracDir + '/queued_post_commits_errors.txt'
postCommitScriptPath = '/home/user/packages/share/trac/contrib/trac-post-commit-hook'
tracURL = 'http://trac.domain.com/project_name/'
errorEmailTo = 'info@domain.com'

queuedCommits = Array.new
begin
File.open(logFilePath, "r") do |file|
file.each_line do |line|
queuedCommits < < line
end
end
rescue
# no queued commits to process
exit
end

# Empty out the file
system("> #{logFilePath}")

queuedCommits.each do |line|
line.chomp!
repo,rev = line.split(':')
next unless repo and rev

logMessage = `/usr/bin/svnlook log -r #{rev} #{repo}`
author = `/usr/bin/svnlook author -r #{rev} #{repo}`

# to make sure python can fine the trac module
exportCmd = 'export PYTHONPATH="$HOME/packages/lib/python2.4/site-packages/:$PYTHONPATH"'
postCommitCmd = %{/home/user/packages/bin/python  #{postCommitScriptPath} -p "#{tracDir}" -r "#{rev}" -u "#{author}" -m "#{logMessage}" -s "#{tracURL}"}

if system("#{exportCmd}; #{postCommitCmd}")
# log the success
File.open(doneFilePath, "a") do |file|
file.puts("#{Time.now}:#{repo}:#{rev}:#{author}:#{logMessage}")
end
else
# write an error
errorCode = $?
File.open(errorFilePath, "a") do |file|
file.puts("#{Time.now}:#{errorCode}:#{repo}:#{rev}:#{author}:#{logMessage}")
end
# and put the commit info back in the queue file
File.open(logFilePath, "a") do |file|
file.puts line
end
# send an email
system("echo #{errorFilePath} | mail -s 'Post Commit Errors' #{errorEmailTo}")
end
end

File: ~/svn/project_name/hooks/post-commit

#!/bin/sh

REPOS="$1"
REV="$2"

# Just append this info to the log file
echo "$REPOS:$REV" && /home/user/trac_projects/project_name/queued_commits.txt

Some resources I used in putting together the above information:

I stumbled upon an intriguing alternative to Trac: Warehouse. As nice as Trac is, I was never 100% thrilled with its user interface and user management functionality. Warehouse looks to have a beautiful user interface and its user management functionality seems great. It is much closer to a GitHub like interface than most other project management systems I’ve seen lately.

Although svn is a great system, git seems eliminate any frustration still lingering in the svn workflow. Unfortunately I have many build scripts that are built around my svn repositories to it is going to be awhile before I can fully make the transition. However, it seems to be fairly simply to get git up and running on a shared server systemMatt Gemmel posted a nice review of Linode; $20/month for 356MB of ram and 16 HD space doesn’t seem bad at all.

PHP: Framework Faceoff

I was away from the PHP world while traveling in Europe and in four short months some nice PHP MVC frameworks seemed to crop up out of nowhere. I’m starting a fairly large project and was determined to use one of these new frameworks as the design and ‘free’ functionality that they offered seemed too good to pass up. However, there was almost too many choices. It was hard to choose between: Cake PHP, Code Igniter, Akelos, PHP Dev Shell, and many others.

For me it ended up coming down to Code Igniter (CI) and Kohana. Kohana is actually a branch off of the CI codebase, keeping with alot of the design choices that make CI attractive, yet stripping the codebase of support for PHP4 and some other legacy technologies and adding support for some of the more advanced PHP5 features. In short Kohana seems like a clean, lean, more ‘modern’ version of CI. I’ve been developing with it for a week and highly recommend checking it out. One of the features I’ve been most impressed by is ORM which uses SQL schema extrapolated from the source database to create a editable object that can perform all CRUD operations. This means only one or two lines of ‘glue code’ to handle the M of the MVC design pattern – Cocoa Bindings for PHP!

The community around Kohana is very impressive for a fairly new PHP framework, I’ve found some very nice addons which have saved me hours of development time:

  • Formo – Easy form creation and validation
  • Message – Easy error/info messages across PHP sessions
  • Head – Dynamic head creation using PHP
  • s7nCMS – Nice CMS package
  • And much much more

I’ve even posted one of my small extensions.

Regex Revisited: Ack, SED, and TextMate

Grep has long been considered the de-facto regex command line tool for unix developers, but I’ve never really liked it. Grep has always seemed slow, buggy, and limited in its regex capabilities; I always resorted to using the built in regex functionality of TextMate or Python’s built in regex abilities.

As great as Python and TextMate are, they are not a clean solution to a simple problem and do not play nicely with shell scripting. Thankfully I’ve finally found a regex tool that fulfills my expectations: ack. There is an even a “Ack in Project” TextMate Plugin (so long Grep in Project) which works blazingly fast. Combine ack with the fixed and fully functional macports gsed (aka GNU sed) and I my command line text processing facilities are finally what they should be.

On a quick side note, I’ve come across another nice plugin for TextMate: ProjectPlus. ProjectPlus adds some nice UI as well as functional additions to the standard project drawer, it’ll help hold me over until TextMate 2.0 comes around.