Hudson notifications with libnotify
I've been using a Gnome-based desktop for about the past 8-9 months and one of the things I've come to really appreciate is that most Gnome applications integrate with "libnotify". Libnotify is a simple Windows taskbar-like notification system that presents status messages at the bottom of your screen. Like all great pieces of software, it has a solid Python interface which allows for incorporating it in those little 10-minutes scripts I find myself writing every now and again.One of the things I wanted to script was the notification of the build status of the numerous jobs that we're running in our Hudson instance here at Slide. Using the Universal Feed Parser and pynotify (listed under "notify-python"), I had a good little Gnome Hudson Notifier running in less than 10 minutes.

Source code after the jump.
import feedparser
import pynotify
import time
BASE_TITLE = 'Hudson Update!'
def success(job):
n = pynotify.Notification(BASE_TITLE,
'"%s" successfully built :)' % job,
'file:///usr/share/pixmaps/gnome-suse.png')
n.set_urgency(pynotify.URGENCY_LOW)
return n
def unstable(job):
return pynotify.Notification(BASE_TITLE,
'"%s" is unstable :-/' % job,
'file:///usr/share/pixmaps/gnome-suse.png')
def failure(job):
n = pynotify.Notification(BASE_TITLE,
'"%s" failed!' % job,
'file:///usr/share/pixmaps/gnome-suse.png')
n.set_urgency(pynotify.URGENCY_CRITICAL)
return n
def main():
pynotify.init('Hudson Notify')
old_items = []
while True:
feed = feedparser.parse('http://hudson/rssLatest')
items = [t['title'] for t in feed['entries']]
new_items = list(set(old_items).difference(items))
for i in new_items:
i = i.split(' ')
job, build, status = (i[0], i[1], i[2])
status = status.replace('(', '').replace(')','')
if status == 'SUCCESS':
success(job).show()
elif status == 'UNSTABLE':
unstable(job).show()
elif status == 'FAILURE':
failure(job).show()
old_items = items
time.sleep(60)
if __name__ == '__main__':
main()
It's pretty basic right now, but does everything I really wanted it to do. I may add it into a public Git repository in the near future if I spend any more time on the project. Hope you like it :)
academia activerecord ada android apture bart beer birthday brainfuck buzzwords c campdevops cheetah chrome ci cocoa conference continuousdeployment cucumber devops documentation drupal evernote facebook family fosdem fosdem2012 ganglia gerrit git graphite home hudson identica javascript jekyll jenkins jenkinsci jenkinsconf justintv learnings linux literature livecoding lookout media meetups microblogging miscellaneous mono offtopic opbart openmoko opensource opinion parrots photos presentation programming protesting puppet python rails rdoc redis ri ruby running scale scale10x screencast slide smalltalk soapopera software development sonic stupidhacks tablet tripdiary twitter twos usenet vagrant wtf
