Skip to content

Instantly share code, notes, and snippets.

@zpao
Created March 24, 2009 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zpao/84210 to your computer and use it in GitHub Desktop.
Save zpao/84210 to your computer and use it in GitHub Desktop.
#!/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:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment