Add ICU message format support
[chromium-blink-merge.git] / tools / security / check_message_owners.py
blobb3793f6fb34c751e3da45e02bab76174ccf0adfa
1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Make sure all of the per-file *_messages.h OWNERS are consistent"""
8 import os
9 import re
10 import sys
12 def main():
13 file_path = os.path.dirname(__file__);
14 root_dir = os.path.abspath(os.path.join(file_path, '..', '..'))
15 owners = collect_owners(root_dir)
16 all_owners = get_all_owners(owners)
17 print_missing_owners(owners, all_owners)
18 return 0
20 def collect_owners(root_dir):
21 result = {}
22 for root, dirs, files in os.walk(root_dir):
23 if "OWNERS" in files:
24 owner_file_path = os.path.join(root, "OWNERS")
25 owner_set = extract_owners_from_file(owner_file_path)
26 if owner_set:
27 result[owner_file_path] = owner_set
28 return result
30 def extract_owners_from_file(owner_file_path):
31 result = set()
32 regexp = re.compile('^per-file.*_messages[^=]*=\s*(.*)@([^#]*)')
33 with open(owner_file_path) as f:
34 for line in f:
35 match = regexp.match(line)
36 if match:
37 result.add(match.group(1).strip())
38 return result
40 def get_all_owners(owner_dict):
41 result = set()
42 for key in owner_dict:
43 result = result.union(owner_dict[key])
44 return result
46 def print_missing_owners(owner_dict, owner_set):
47 for key in owner_dict:
48 for owner in owner_set:
49 if not owner in owner_dict[key]:
50 print key + " is missing " + owner
52 if '__main__' == __name__:
53 sys.exit(main())