From f77c7f75e55af504db3905745b424b800d75d7d1 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Wed, 15 Aug 2018 16:07:27 -0700 Subject: [PATCH] Use multiple globs/emails in per-file syntax Bug: 112259427 Test: tools/checkowners.py -c -v OWNERS */OWNERS */*/OWNERS Change-Id: I0e2c2c64a23df360fbe7691c4336ca04099fba13 --- OWNERS | 7 ++----- core/OWNERS | 9 +-------- tools/OWNERS | 3 +-- tools/checkowners.py | 42 +++++++++++++++++++++++++----------------- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/OWNERS b/OWNERS index 1e9b7634f..b9fee4e1a 100644 --- a/OWNERS +++ b/OWNERS @@ -2,10 +2,7 @@ ccross@android.com dwillemsen@google.com nanzhang@google.com -per-file * = ccross@android.com -per-file * = dwillemsen@google.com -per-file * = nanzhang@google.com +per-file * = ccross@android.com,dwillemsen@google.com,nanzhang@google.com # for version updates -per-file version_defaults.mk = aseaton@google.com -per-file version_defaults.mk = elisapascual@google.com +per-file version_defaults.mk = aseaton@google.com,elisapascual@google.com diff --git a/core/OWNERS b/core/OWNERS index 4045061da..570ede8a4 100644 --- a/core/OWNERS +++ b/core/OWNERS @@ -1,8 +1 @@ -per-file * = ccross@android.com -per-file * = dwillemsen@google.com -per-file * = nanzhang@google.com - -per-file dex_preopt*.mk = ngeoffray@google.com -per-file dex_preopt*.mk = calin@google.com -per-file dex_preopt*.mk = mathewi@google.com -per-file dex_preopt*.mk = dbrazdil@google.com +per-file dex_preopt*.mk = ngeoffray@google.com,calin@google.com,mathewi@google.com,dbrazdil@google.com diff --git a/tools/OWNERS b/tools/OWNERS index 7a23adce9..7d666f168 100644 --- a/tools/OWNERS +++ b/tools/OWNERS @@ -1,2 +1 @@ -per-file warn.py = chh@google.com -per-file checkowners.py = chh@google.com +per-file warn.py,checkowners.py = chh@google.com diff --git a/tools/checkowners.py b/tools/checkowners.py index 54198a7e9..8568ccf86 100755 --- a/tools/checkowners.py +++ b/tools/checkowners.py @@ -35,22 +35,31 @@ def find_address(address): echo('Checking email address: ' + address) result = urllib2.urlopen(request).read() checked_addresses[address] = result.find('"_account_id":') >= 0 + if checked_addresses[address]: + echo('Found email address: ' + address) return checked_addresses[address] +def check_address(fname, num, address): + if find_address(address): + return 0 + print '%s:%d: ERROR: unknown email address: %s' % (fname, num, address) + return 1 + + def main(): # One regular expression to check all valid lines. noparent = 'set +noparent' email = '([^@ ]+@[^ @]+|\\*)' - directive = '(%s|%s)' % (email, noparent) + emails = '(%s( *, *%s)*)' % (email, email) + directive = '(%s|%s)' % (emails, noparent) glob = '[a-zA-Z0-9_\\.\\-\\*\\?]+' - perfile = 'per-file +' + glob + ' *= *' + directive + globs = '(%s( *, *%s)*)' % (glob, glob) + perfile = 'per-file +' + globs + ' *= *' + directive pats = '(|%s|%s|%s)$' % (noparent, email, perfile) patterns = re.compile(pats) - - # One pattern to capture email address. - email_address = '.*(@| |=|^)([^@ =]+@[^ @]+)' - address_pattern = re.compile(email_address) + address_pattern = re.compile('([^@ ]+@[^ @]+)') + perfile_pattern = re.compile('per-file +.*=(.*)') error = 0 for fname in args.owners: @@ -60,17 +69,16 @@ def main(): num += 1 stripped_line = re.sub('#.*$', '', line).strip() if not patterns.match(stripped_line): - error = 1 - print('%s:%d: ERROR: unknown line [%s]' - % (fname, num, line.strip())) - elif args.check_address and address_pattern.match(stripped_line): - address = address_pattern.match(stripped_line).group(2) - if find_address(address): - echo('Found email address: ' + address) - else: - error = 1 - print('%s:%d: ERROR: unknown email address: %s' - % (fname, num, address)) + error += 1 + print '%s:%d: ERROR: unknown line [%s]' % (fname, num, line.strip()) + elif args.check_address: + if perfile_pattern.match(stripped_line): + for addr in perfile_pattern.match(stripped_line).group(1).split(','): + a = addr.strip() + if a and a != '*': + error += check_address(fname, num, addr.strip()) + elif address_pattern.match(stripped_line): + error += check_address(fname, num, stripped_line) sys.exit(error) if __name__ == '__main__':