OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Interactive tool for finding reviewers/owners for a change.""" | 5 """Interactive tool for finding reviewers/owners for a change.""" |
6 | 6 |
7 import os | 7 import os |
8 import copy | 8 import copy |
9 import owners as owners_module | 9 import owners as owners_module |
10 | 10 |
11 | 11 |
12 def first(iterable): | 12 def first(iterable): |
13 for element in iterable: | 13 for element in iterable: |
14 return element | 14 return element |
15 | 15 |
16 | 16 |
17 class OwnersFinder(object): | 17 class OwnersFinder(object): |
18 COLOR_LINK = '\033[4m' | 18 COLOR_LINK = '\033[4m' |
19 COLOR_BOLD = '\033[1;32m' | 19 COLOR_BOLD = '\033[1;32m' |
20 COLOR_GREY = '\033[0;37m' | 20 COLOR_GREY = '\033[0;37m' |
21 COLOR_RESET = '\033[0m' | 21 COLOR_RESET = '\033[0m' |
22 | 22 |
23 indentation = 0 | 23 indentation = 0 |
24 | 24 |
25 def __init__(self, files, local_root, author, | 25 def __init__(self, files, local_root, author, |
26 fopen, os_path, glob, | 26 fopen, os_path, |
27 email_postfix='@chromium.org', | 27 email_postfix='@chromium.org', |
28 disable_color=False): | 28 disable_color=False): |
29 self.email_postfix = email_postfix | 29 self.email_postfix = email_postfix |
30 | 30 |
31 if os.name == 'nt' or disable_color: | 31 if os.name == 'nt' or disable_color: |
32 self.COLOR_LINK = '' | 32 self.COLOR_LINK = '' |
33 self.COLOR_BOLD = '' | 33 self.COLOR_BOLD = '' |
34 self.COLOR_GREY = '' | 34 self.COLOR_GREY = '' |
35 self.COLOR_RESET = '' | 35 self.COLOR_RESET = '' |
36 | 36 |
37 self.db = owners_module.Database(local_root, fopen, os_path, glob) | 37 self.db = owners_module.Database(local_root, fopen, os_path) |
38 self.db.load_data_needed_for(files) | 38 self.db.load_data_needed_for(files) |
39 | 39 |
40 self.os_path = os_path | 40 self.os_path = os_path |
41 | 41 |
42 self.author = author | 42 self.author = author |
43 | 43 |
44 filtered_files = files | 44 filtered_files = files |
45 | 45 |
46 # Eliminate files that author himself can review. | 46 # Eliminate files that the author can review. |
47 if author: | 47 filtered_files = list(self.db.files_not_covered_by( |
48 if author in self.db.owned_by: | 48 filtered_files, [author] if author else [])) |
49 for dir_name in self.db.owned_by[author]: | |
50 filtered_files = [ | |
51 file_name for file_name in filtered_files | |
52 if not file_name.startswith(dir_name)] | |
53 | |
54 filtered_files = list(filtered_files) | |
55 | |
56 # Eliminate files that everyone can review. | |
57 if owners_module.EVERYONE in self.db.owned_by: | |
58 for dir_name in self.db.owned_by[owners_module.EVERYONE]: | |
59 filtered_files = filter( | |
60 lambda file_name: not file_name.startswith(dir_name), | |
61 filtered_files) | |
62 | 49 |
63 # If some files are eliminated. | 50 # If some files are eliminated. |
64 if len(filtered_files) != len(files): | 51 if len(filtered_files) != len(files): |
65 files = filtered_files | 52 files = filtered_files |
66 # Reload the database. | 53 # Reload the database. |
67 self.db = owners_module.Database(local_root, fopen, os_path, glob) | 54 self.db = owners_module.Database(local_root, fopen, os_path) |
68 self.db.load_data_needed_for(files) | 55 self.db.load_data_needed_for(files) |
69 | 56 |
70 self.all_possible_owners = self.db.all_possible_owners(files, None) | 57 self.all_possible_owners = self.db.all_possible_owners(files, None) |
71 | 58 |
72 self.owners_to_files = {} | 59 self.owners_to_files = {} |
73 self._map_owners_to_files(files) | 60 self._map_owners_to_files(files) |
74 | 61 |
75 self.files_to_owners = {} | 62 self.files_to_owners = {} |
76 self._map_files_to_owners() | 63 self._map_files_to_owners() |
77 | 64 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 def print_info(self, owner): | 343 def print_info(self, owner): |
357 self.hr() | 344 self.hr() |
358 self.writeln( | 345 self.writeln( |
359 self.bold(str(len(self.unreviewed_files))) + ' file(s) left.') | 346 self.bold(str(len(self.unreviewed_files))) + ' file(s) left.') |
360 self.print_owned_files_for(owner) | 347 self.print_owned_files_for(owner) |
361 | 348 |
362 def input_command(self, owner): | 349 def input_command(self, owner): |
363 self.writeln('Add ' + self.bold_name(owner) + ' as your reviewer? ') | 350 self.writeln('Add ' + self.bold_name(owner) + ' as your reviewer? ') |
364 return raw_input( | 351 return raw_input( |
365 '[yes/no/Defer/pick/files/owners/quit/restart]: ').lower() | 352 '[yes/no/Defer/pick/files/owners/quit/restart]: ').lower() |
OLD | NEW |