michael@0: import difflib michael@0: import logging michael@0: import re michael@0: import urllib2 michael@0: from util.commands import run_cmd, get_output michael@0: from util.hg import get_repo_name, make_hg_url michael@0: from subprocess import CalledProcessError michael@0: michael@0: log = logging.getLogger(__name__) michael@0: michael@0: michael@0: def check_buildbot(): michael@0: """check if buildbot command works""" michael@0: try: michael@0: run_cmd(['buildbot', '--version']) michael@0: except CalledProcessError: michael@0: log.error("FAIL: buildbot command doesn't work", exc_info=True) michael@0: raise michael@0: michael@0: michael@0: def find_version(contents, versionNumber): michael@0: """Given an open readable file-handle look for the occurrence michael@0: of the version # in the file""" michael@0: ret = re.search(re.compile(re.escape(versionNumber), re.DOTALL), contents) michael@0: return ret michael@0: michael@0: michael@0: def locale_diff(locales1, locales2): michael@0: """ accepts two lists and diffs them both ways, returns any differences michael@0: found """ michael@0: diff_list = [locale for locale in locales1 if not locale in locales2] michael@0: diff_list.extend(locale for locale in locales2 if not locale in locales1) michael@0: return diff_list michael@0: michael@0: michael@0: def get_buildbot_username_param(): michael@0: cmd = ['buildbot', 'sendchange', '--help'] michael@0: output = get_output(cmd) michael@0: if "-W, --who=" in output: michael@0: return "--who" michael@0: else: michael@0: return "--username" michael@0: michael@0: michael@0: def sendchange(branch, revision, username, master, products): michael@0: """Send the change to buildbot to kick off the release automation""" michael@0: if isinstance(products, basestring): michael@0: products = [products] michael@0: cmd = [ michael@0: 'buildbot', michael@0: 'sendchange', michael@0: get_buildbot_username_param(), michael@0: username, michael@0: '--master', michael@0: master, michael@0: '--branch', michael@0: branch, michael@0: '-p', michael@0: 'products:%s' % ','.join(products), michael@0: '-p', michael@0: 'script_repo_revision:%s' % revision, michael@0: 'release_build' michael@0: ] michael@0: logging.info("Executing: %s" % cmd) michael@0: run_cmd(cmd) michael@0: michael@0: michael@0: def verify_mozconfigs(mozconfig_pair, nightly_mozconfig_pair, platform, michael@0: mozconfigWhitelist={}): michael@0: """Compares mozconfig to nightly_mozconfig and compare to an optional michael@0: whitelist of known differences. mozconfig_pair and nightly_mozconfig_pair michael@0: are pairs containing the mozconfig's identifier and the list of lines in michael@0: the mozconfig.""" michael@0: michael@0: # unpack the pairs to get the names, the names are just for michael@0: # identifying the mozconfigs when logging the error messages michael@0: mozconfig_name, mozconfig_lines = mozconfig_pair michael@0: nightly_mozconfig_name, nightly_mozconfig_lines = nightly_mozconfig_pair michael@0: michael@0: missing_args = mozconfig_lines == [] or nightly_mozconfig_lines == [] michael@0: if missing_args: michael@0: log.info("Missing mozconfigs to compare for %s" % platform) michael@0: return False michael@0: michael@0: success = True michael@0: michael@0: diffInstance = difflib.Differ() michael@0: diff_result = diffInstance.compare(mozconfig_lines, nightly_mozconfig_lines) michael@0: diffList = list(diff_result) michael@0: michael@0: for line in diffList: michael@0: clean_line = line[1:].strip() michael@0: if (line[0] == '-' or line[0] == '+') and len(clean_line) > 1: michael@0: # skip comment lines michael@0: if clean_line.startswith('#'): michael@0: continue michael@0: # compare to whitelist michael@0: message = "" michael@0: if line[0] == '-': michael@0: if platform in mozconfigWhitelist.get('release', {}): michael@0: if clean_line in \ michael@0: mozconfigWhitelist['release'][platform]: michael@0: continue michael@0: elif line[0] == '+': michael@0: if platform in mozconfigWhitelist.get('nightly', {}): michael@0: if clean_line in \ michael@0: mozconfigWhitelist['nightly'][platform]: michael@0: continue michael@0: else: michael@0: log.warning("%s not in %s %s!" % ( michael@0: clean_line, platform, michael@0: mozconfigWhitelist['nightly'][platform])) michael@0: else: michael@0: log.error("Skipping line %s!" % line) michael@0: continue michael@0: message = "found in %s but not in %s: %s" michael@0: if line[0] == '-': michael@0: log.error(message % (mozconfig_name, michael@0: nightly_mozconfig_name, clean_line)) michael@0: else: michael@0: log.error(message % (nightly_mozconfig_name, michael@0: mozconfig_name, clean_line)) michael@0: success = False michael@0: return success