Backout a74bd5095902, Bug 959405 - Please update the Buri Moz-central, 1.3, 1.2 with...
[gecko.git] / build / release / sanity.py
blobcd89eb3d77cfb1a7b0930c3fd2429a444a50c710
1 import difflib
2 import logging
3 import re
4 import urllib2
5 from util.commands import run_cmd, get_output
6 from util.hg import get_repo_name, make_hg_url
7 from subprocess import CalledProcessError
9 log = logging.getLogger(__name__)
12 def check_buildbot():
13 """check if buildbot command works"""
14 try:
15 run_cmd(['buildbot', '--version'])
16 except CalledProcessError:
17 log.error("FAIL: buildbot command doesn't work", exc_info=True)
18 raise
21 def find_version(contents, versionNumber):
22 """Given an open readable file-handle look for the occurrence
23 of the version # in the file"""
24 ret = re.search(re.compile(re.escape(versionNumber), re.DOTALL), contents)
25 return ret
28 def locale_diff(locales1, locales2):
29 """ accepts two lists and diffs them both ways, returns any differences
30 found """
31 diff_list = [locale for locale in locales1 if not locale in locales2]
32 diff_list.extend(locale for locale in locales2 if not locale in locales1)
33 return diff_list
36 def get_buildbot_username_param():
37 cmd = ['buildbot', 'sendchange', '--help']
38 output = get_output(cmd)
39 if "-W, --who=" in output:
40 return "--who"
41 else:
42 return "--username"
45 def sendchange(branch, revision, username, master, products):
46 """Send the change to buildbot to kick off the release automation"""
47 if isinstance(products, basestring):
48 products = [products]
49 cmd = [
50 'buildbot',
51 'sendchange',
52 get_buildbot_username_param(),
53 username,
54 '--master',
55 master,
56 '--branch',
57 branch,
58 '-p',
59 'products:%s' % ','.join(products),
60 '-p',
61 'script_repo_revision:%s' % revision,
62 'release_build'
64 logging.info("Executing: %s" % cmd)
65 run_cmd(cmd)
68 def verify_mozconfigs(mozconfig_pair, nightly_mozconfig_pair, platform,
69 mozconfigWhitelist={}):
70 """Compares mozconfig to nightly_mozconfig and compare to an optional
71 whitelist of known differences. mozconfig_pair and nightly_mozconfig_pair
72 are pairs containing the mozconfig's identifier and the list of lines in
73 the mozconfig."""
75 # unpack the pairs to get the names, the names are just for
76 # identifying the mozconfigs when logging the error messages
77 mozconfig_name, mozconfig_lines = mozconfig_pair
78 nightly_mozconfig_name, nightly_mozconfig_lines = nightly_mozconfig_pair
80 missing_args = mozconfig_lines == [] or nightly_mozconfig_lines == []
81 if missing_args:
82 log.info("Missing mozconfigs to compare for %s" % platform)
83 return False
85 success = True
87 diffInstance = difflib.Differ()
88 diff_result = diffInstance.compare(mozconfig_lines, nightly_mozconfig_lines)
89 diffList = list(diff_result)
91 for line in diffList:
92 clean_line = line[1:].strip()
93 if (line[0] == '-' or line[0] == '+') and len(clean_line) > 1:
94 # skip comment lines
95 if clean_line.startswith('#'):
96 continue
97 # compare to whitelist
98 message = ""
99 if line[0] == '-':
100 if platform in mozconfigWhitelist.get('release', {}):
101 if clean_line in \
102 mozconfigWhitelist['release'][platform]:
103 continue
104 elif line[0] == '+':
105 if platform in mozconfigWhitelist.get('nightly', {}):
106 if clean_line in \
107 mozconfigWhitelist['nightly'][platform]:
108 continue
109 else:
110 log.warning("%s not in %s %s!" % (
111 clean_line, platform,
112 mozconfigWhitelist['nightly'][platform]))
113 else:
114 log.error("Skipping line %s!" % line)
115 continue
116 message = "found in %s but not in %s: %s"
117 if line[0] == '-':
118 log.error(message % (mozconfig_name,
119 nightly_mozconfig_name, clean_line))
120 else:
121 log.error(message % (nightly_mozconfig_name,
122 mozconfig_name, clean_line))
123 success = False
124 return success