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,
return n

def unstable(job):
return pynotify.Notification(BASE_TITLE,
'"%s" is unstable :-/' % job,

def failure(job):
n = pynotify.Notification(BASE_TITLE,
'"%s" failed!' % job,
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':
elif status == 'UNSTABLE':
elif status == 'FAILURE':

old_items = items

if __name__ == '__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 :)
comments powered by Disqus