GeekTool is awesome. Is the Tree Green? is awesome. So together they are SUPER AWESOME!

isthetreegreen.py + GeekTool by zpao, on Flickr

Python?

Historically, I’m a Ruby guy, but I started learning Python for a Django project I’m (barely) working on. So I picked up a book here at work & decided to flex my pythons a little bit. You can laugh, it’s punny.

The first pass of this took me ~20 minutes, and I just tidied it up this morning so it would take command line options.

How?

If you’re reading this and actually need to know whether or not the tree is green, then you should be able to figure it out. GeekTool is OS X only, but there are similar programs for Windows and Linux.

It’s easy enough to do what I did in the image above. The program can take 2 arguments treename and output. Run it with -h for usage.

Code?

#!/usr/bin/env python
# Based on Is the Tree Green? <http://isthetreegreen.com>
# Original Code & Concept by Justin Dolske <dolske@mozilla.com>
# Ported to Python by Paul O'Shannessy <paul@zpao.com>
import getopt, sys
from urllib import urlopen
def main(argv):
"""docstring for main"""
treename = "Firefox"
output = "all"
try:
opts, args = getopt.getopt(argv, "ht:o:", ["help", "treename=", "output="])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
elif opt in ("-t", "--treename"):
treename = arg
elif opt in ("-o", "--output"):
output = arg
is_the_tree_green(treename, output)
def usage():
"""outputs the usage of this program"""
print """
Prints the current status of tinderbox. While perhaps useful from the command
line for a quick update before checking in (in case you're too lazy to check
tinderbox). It's more fun to show it off on your desktop using GeekTool
<http://projects.tynsoe.org>
Original concept: Justin Dolkse and his <http://isthetreegreen.com>
-t, --trename= The tree to use, default is 'Firefox'
-o, --output= The output type. Valid options are 'status', 'message',
and 'all'. Default is 'all'
"""
def is_the_tree_green(treename="Firefox", output="all"):
"""docstring for is_the_tree_green"""
content = urlopen("http://tinderbox.mozilla.org/%s/quickparse.txt" % treename).read()
lines = content.lstrip().rstrip().split("\n")
num_boxes = num_red = num_orange = num_green = 0
for line in lines[:]:
[build, tree, ident, state, num] = line.rstrip("|").split("|")
if ident == "static-analyis-bsmedberg":
continue
num_boxes += 1
if state == "success":
num_green += 1
elif state == "testfailed":
num_orange += 1
elif state == "busted":
num_red += 1
elif state == "open" or state == "closed":
# Ignore the overall tree status on Firefox3.0 (CVS/Bonsai)
num_boxes -= 1
status = get_status(num_boxes, num_red, num_orange, num_green)
message = get_message(num_boxes, num_red, num_orange, num_green)
if output == "status":
print status
elif output == "message":
print message
else:
print "%s - %s" % (status, message)
def get_status(total, red, orange, green):
if not (red + orange + green) == total:
return "Maybe?"
elif green == total:
return "Yes!"
else:
return "No."
def get_message(total, red, orange, green):
if not (red + orange + green) == total:
message = "I didn't understand the Tinderbox status..."
elif green == total:
message = "Everything is SUPER!"
else:
if red and not orange:
message = ("1 box is" if red == 1 else "%d boxes are" % red) + " burning!"
elif not red and orange:
message = "Tests failed on" + (" 1 box!" if orange == 1 else " %d boxes!" % orange)
else:
message = ("1 box is" if red == 1 else "%d boxes are" % red) + " burning, and"
message += " tests failed on" + (" 1 box!" if orange == 1 else " %d boxes!" % orange)
return message
if __name__ == "__main__":
main(sys.argv[1:])

A big thanks to Justin Dolske for Is the Tree Green?. He deserves more credit for this than I.