Chromium Code Reviews| Index: Tools/Scripts/webkitpy/common/net/sheriff_calendar.py |
| diff --git a/Tools/Scripts/webkitpy/common/net/sheriff_calendar.py b/Tools/Scripts/webkitpy/common/net/sheriff_calendar.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5af9ef9b71fb44e7b3744292739f4f8c5bc470f8 |
| --- /dev/null |
| +++ b/Tools/Scripts/webkitpy/common/net/sheriff_calendar.py |
| @@ -0,0 +1,56 @@ |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import re |
| +import urllib2 |
| + |
| +# FIXME: This probably belongs in config.py? |
| +BLINK_SHERIFF_URL = ( |
| + 'http://build.chromium.org/p/chromium.webkit/sheriff_webkit.js') |
| + |
| + |
| +# Does not support unicode or special characters. |
| +VALID_EMAIL_REGEXP = re.compile(r'^[A-Za-z0-9\.&\'\+-/=_]+@' |
| + '[A-Za-z0-9\.-]+$') |
|
ojan
2014/06/01 02:59:09
Nit: Why the linewrap?
|
| + |
| + |
| +def _complete_email(name): |
|
ojan
2014/06/01 02:59:09
All these functions should be super easy to unitte
|
| + """If the name does not include '@', append '@chromium.org'.""" |
| + if '@' not in name: |
| + return name + '@chromium.org' |
| + return name |
| + |
| + |
| +def _names_from_sheriff_js(sheriff_js): |
| + match = re.match(r'document.write\(\'(.*)\'\)', sheriff_js) |
| + emails_string = match.group(1) |
| + # Detect 'none (channel is sheriff)' text and ignore it. |
| + if 'channel is sheriff' in emails_string.lower(): |
| + return [] |
| + return map(str.strip, emails_string.split(',')) |
| + |
| + |
| +def _email_is_valid(email): |
| + """Determines whether the given email address is valid.""" |
| + return VALID_EMAIL_REGEXP.match(email) is not None |
| + |
| + |
| +def _filter_emails(emails): |
| + """Returns the given list with any invalid email addresses removed.""" |
| + rv = [] |
| + for email in emails: |
| + if _email_is_valid(email): |
| + rv.append(email) |
| + else: |
| + print 'WARNING: Not including %s (invalid email address)' % email |
| + return rv |
| + |
| + |
| +def _emails_from_url(sheriff_url): |
| + sheriff_js = urllib2.urlopen(sheriff_url).read() |
| + return map(_complete_email, _names_from_sheriff_js(sheriff_js)) |
| + |
| + |
| +def current_gardener_emails(): |
| + return _emails_from_url(BLINK_SHERIFF_URL) |