OLD | NEW |
---|---|
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 """A database of OWNERS files.""" | 5 """A database of OWNERS files.""" |
6 | 6 |
7 import collections | 7 import collections |
8 import re | 8 import re |
9 | 9 |
10 | 10 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 | 140 |
141 def _read_owners_in_dir(self, dirpath): | 141 def _read_owners_in_dir(self, dirpath): |
142 owners_path = self.os_path.join(self.root, dirpath, 'OWNERS') | 142 owners_path = self.os_path.join(self.root, dirpath, 'OWNERS') |
143 if not self.os_path.exists(owners_path): | 143 if not self.os_path.exists(owners_path): |
144 return | 144 return |
145 | 145 |
146 lineno = 0 | 146 lineno = 0 |
147 for line in self.fopen(owners_path): | 147 for line in self.fopen(owners_path): |
148 lineno += 1 | 148 lineno += 1 |
149 line = line.strip() | 149 line = line.strip() |
150 if line.startswith('#'): | 150 if line.startswith('#') or line == '': |
M-A Ruel
2011/06/08 21:12:43
if line.startswith('#') or not line:
| |
151 continue | 151 continue |
152 if line == 'set noparent': | 152 if line == 'set noparent': |
153 self.stop_looking.add(dirpath) | 153 self.stop_looking.add(dirpath) |
154 continue | 154 continue |
155 if line.startswith('set '): | 155 if line.startswith('set '): |
156 raise SyntaxErrorInOwnersFile(owners_path, lineno, | 156 raise SyntaxErrorInOwnersFile(owners_path, lineno, |
157 'unknown option: "%s"' % line[4:].strip()) | 157 'unknown option: "%s"' % line[4:].strip()) |
158 if self.email_regexp.match(line) or line == EVERYONE: | 158 if self.email_regexp.match(line) or line == EVERYONE: |
159 self.owned_by.setdefault(line, set()).add(dirpath) | 159 self.owned_by.setdefault(line, set()).add(dirpath) |
160 self.owners_for.setdefault(dirpath, set()).add(line) | 160 self.owners_for.setdefault(dirpath, set()).add(line) |
161 continue | 161 continue |
162 raise SyntaxErrorInOwnersFile(owners_path, lineno, | 162 raise SyntaxErrorInOwnersFile(owners_path, lineno, |
163 ('line is not a comment, a "set" directive, ' | 163 ('line is not a comment, a "set" directive, ' |
164 'or an email address: "%s"' % line)) | 164 'or an email address: "%s"' % line)) |
165 | 165 |
166 def _covering_set_of_owners_for(self, files): | 166 def _covering_set_of_owners_for(self, files): |
167 # TODO(dpranke): implement the greedy algorithm for covering sets, and | 167 # TODO(dpranke): implement the greedy algorithm for covering sets, and |
168 # consider returning multiple options in case there are several equally | 168 # consider returning multiple options in case there are several equally |
169 # short combinations of owners. | 169 # short combinations of owners. |
170 every_owner = set() | 170 every_owner = set() |
171 for f in files: | 171 for f in files: |
172 dirname = self.os_path.dirname(f) | 172 dirname = self.os_path.dirname(f) |
173 while dirname in self.owners_for: | 173 while dirname in self.owners_for: |
174 every_owner |= self.owners_for[dirname] | 174 every_owner |= self.owners_for[dirname] |
175 if self._stop_looking(dirname): | 175 if self._stop_looking(dirname): |
176 break | 176 break |
177 dirname = self.os_path.dirname(dirname) | 177 dirname = self.os_path.dirname(dirname) |
178 return every_owner | 178 return every_owner |
OLD | NEW |