Skip to content

Instantly share code, notes, and snippets.

@Stubbs
Created March 9, 2011 18:13
Show Gist options
  • Save Stubbs/862667 to your computer and use it in GitHub Desktop.
Save Stubbs/862667 to your computer and use it in GitHub Desktop.
This is a watchr config script that watches all the Python files in the directories specified by the "watch" command. You can specify one for each Django app in your project.
require "ruby-growl"
watch ('project/(.*).py') {|md| code_changed "#{md[0]}"}
def code_changed(file)
# Get the path of the file that changed
dir = File.dirname(file)
test(dir)
end
def test(path)
result = `/usr/bin/python #{path}/tests.py 2>&1`
growl result rescue nil
end
def growl(message)
puts(message)
message = message.split("\n");
growlnotify = `which growlnotify`.chomp
title = message.find { |e| /FAILED/ =~ e } ? "FAILED" : "PASS"
if title == "FAILED"
image = "~/.watchr_images/fail40.png"
info = message.find { |e| /ERROR/ =~ e }
priority = 2
else
image = "~/.watchr_images/pass.png"
info = "Tests pass, carry on ..."
priority = 0
end
g = Growl.new "127.0.0.1", "Watchr", ["ruby-growl Notification"]
g.notify "ruby-growl Notification", title, info, priority
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment