#!/usr/bin/env python # gettinderboxlogs.py - A script which tries to automatically get the url logs # you want from the tinderbox web interface. # # ***** BEGIN LICENSE BLOCK ***** # Version: MPL 1.1/GPL 2.0/LGPL 2.1 # # The contents of this file are subject to the Mozilla Public License Version # 1.1 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS IS" basis, # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License # for the specific language governing rights and limitations under the # License. # # The Original Code is mozilla.org code. # # The Initial Developer of the Original Code is Mozilla Foundation # Portions created by the Initial Developer are Copyright (C) 2010 # the Initial Developer. All Rights Reserved. # # Contributor(s): # Mounir Lamouri (original author) # # Alternatively, the contents of this file may be used under the terms of # either of the GNU General Public License Version 2 or later (the "GPL"), # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), # in which case the provisions of the GPL or the LGPL are applicable instead # of those above. If you wish to allow use of your version of this file only # under the terms of either the GPL or the LGPL, and not to allow others to # use your version of this file under the terms of the MPL, indicate your # decision by deleting the provisions above and replace them with the notice # and other provisions required by the GPL or the LGPL. If you do not delete # the provisions above, a recipient may use your version of this file under # the terms of any one of the MPL, the GPL or the LGPL. # # ***** END LICENSE BLOCK ***** # WARNING: # This script is a two hours work so do not expect it to be error-proof. # For the same reason, class and variables naming may be inappropriate, code # may be not clean and bugs may appears. # If you have any comments, send me an email. from lxml import etree from optparse import OptionParser import sys class TryServerResults: rev = "" url = "" status = "" machine = "" type = "" def __init__(self, rev="", url="", status="", machine="", type=""): self.rev = rev self.url = url self.status = status self.machine = machine self.type = type def __repr__(self): return "status: %s\nurl: %s" % (self.status, self.url) class TryServerParser: inTT = False results = [] currentResult = None nbA = 0 def __init__(self, rev): self.rev = rev def start(self, tag, attrib): if tag == 'tt': self.inTT = True self.nbA = 0 elif self.inTT and tag == 'a': self.nbA += 1 if self.nbA == 1 and 'title' in attrib: self.currentResult = TryServerResults(url=attrib['href'], status=attrib['title']) elif self.nbA == 2 and 'href' in attrib and \ self.rev in attrib['href']: self.currentResult.rev = self.rev self.results.append(self.currentResult) self.currentResult = None # TODO: machine and type # def data(self, data): # if self.inTT and self.foundFirstA: # print("data %r" % data) def end(self, tag): if self.inTT and tag == 'tt': self.inTT = False self.nbA = 0 def close(self): return "closed!" if __name__ == "__main__": tryURL = "http://tinderbox.mozilla.org/showbuilds.cgi?tree=MozillaTry" parser = OptionParser() parser.add_option("-r", "--rev", help="revision to look for") parser.add_option("-a", "--all", action="store_true", help="show all results, even success") parser.add_option("-l", "--long", action="store_true", help="get 24 hours results instead of 12 hours") parser.add_option("-f", "--file", help="use a file instead of looking to the tinderbox") (options, args) = parser.parse_args() if not options.rev: print("Error: -r/--rev is required!") sys.exit() if options.long and options.file: print("Warning: you can't have a long version of a local file!") if options.long: tryURL += "&hours=24" if options.file: tryURL = options.file target = TryServerParser(options.rev) parser = etree.HTMLParser(target=target) etree.parse(tryURL, parser) for r in target.results: # URL isn't absolute in long mode if options.long: r.url = "http://tinderbox.mozilla.org/" + r.url if options.all or r.status != "success": print(r) print("")