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. 5 6"""Make sure all of the per-file *_messages.h OWNERS are consistent""" 7 8import os 9import re 10import sys 11 12def 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 19 20def 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 29 30def 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 39 40def get_all_owners(owner_dict): 41 result = set() 42 for key in owner_dict: 43 result = result.union(owner_dict[key]) 44 return result 45 46def 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 51 52if '__main__' == __name__: 53 sys.exit(main()) 54