Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: owners.py

Issue 6612011: add tests for owners database module in depot_tools (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: make raise_not_found a file-level fn Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/filesystem_mock.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 class Assertion(AssertionError): 7 class Assertion(AssertionError):
8 pass 8 pass
9 9
10
11 class SyntaxError(Exception):
12 def __init__(self, path, line, msg):
13 self.path = path
14 self.line = line
15 self.msg = msg
16
17 def __str__(self):
18 if self.msg:
19 return "%s:%d syntax error: %s" % (self.path, self.line, self.msg)
20 else:
21 return "%s:%d syntax error" % (self.path, self.line)
22
23
24 # Wildcard email-address in the OWNERS file.
25 ANYONE = '*'
26
27
10 class Database(object): 28 class Database(object):
29 """A database of OWNERS files for a repository.
30
31 This class allows you to find a suggested set of reviewers for a list
32 of changed files, and see if a list of changed files is covered by a
33 list of reviewers."""
34
11 def __init__(self, root, fopen, os_path): 35 def __init__(self, root, fopen, os_path):
12 """Initializes the database of owners for a repository. 36 """Args:
13
14 Args:
15 root: the path to the root of the Repository 37 root: the path to the root of the Repository
16 all_owners: the list of every owner in the system 38 all_owners: the list of every owner in the system
17 open: function callback to open a text file for reading 39 open: function callback to open a text file for reading
18 os_path: module/object callback with fields for 'exists', 40 os_path: module/object callback with fields for 'exists',
19 'dirname', and 'join' 41 'dirname', and 'join'
20 """ 42 """
21 self.root = root 43 self.root = root
22 self.fopen = fopen 44 self.fopen = fopen
23 self.os_path = os_path 45 self.os_path = os_path
24 46
25 # Mapping of files to authorized owners. 47 # Mapping of files to authorized owners.
26 self.files_owned_by = {} 48 self.files_owned_by = {}
27 49
28 # Mapping of owners to the files they own. 50 # Mapping of owners to the files they own.
29 self.owners_for = {} 51 self.owners_for = {}
30 52
31 # In-memory cached map of files to their OWNERS files. 53 # In-memory cached map of files to their OWNERS files.
32 self.owners_file_for = {} 54 self.owners_file_for = {}
33 55
34 # In-memory cache of OWNERS files and their contents 56 # In-memory cache of OWNERS files and their contents
35 self.owners_files = {} 57 self.owners_files = {}
36 58
37 def OwnersFor(self, files): 59 def ReviewersFor(self, files):
38 """Returns a sets of reviewers that will cover the set of files. 60 """Returns a suggested set of reviewers that will cover the set of files.
39 61
40 The set of files are paths relative to (and under) self.root.""" 62 The set of files are paths relative to (and under) self.root."""
41 self._LoadDataNeededFor(files) 63 self._LoadDataNeededFor(files)
42 return self._CoveringSetOfOwnersFor(files) 64 return self._CoveringSetOfOwnersFor(files)
43 65
44 def FilesAreCoveredBy(self, files, reviewers): 66 def FilesAreCoveredBy(self, files, reviewers):
45 return not self.FilesNotCoveredBy(files, reviewers) 67 return not self.FilesNotCoveredBy(files, reviewers)
46 68
47 def FilesNotCoveredBy(self, files, reviewers): 69 def FilesNotCoveredBy(self, files, reviewers):
48 covered_files = set() 70 covered_files = set()
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 owners_for.add(owner) 103 owners_for.add(owner)
82 104
83 def _CoveringSetOfOwnersFor(self, files): 105 def _CoveringSetOfOwnersFor(self, files):
84 # TODO(dpranke): implement the greedy algorithm for covering sets, and 106 # TODO(dpranke): implement the greedy algorithm for covering sets, and
85 # consider returning multiple options in case there are several equally 107 # consider returning multiple options in case there are several equally
86 # short combinations of owners. 108 # short combinations of owners.
87 every_owner = set() 109 every_owner = set()
88 for f in files: 110 for f in files:
89 every_owner = every_owner.union(self.owners_for[f]) 111 every_owner = every_owner.union(self.owners_for[f])
90 return every_owner 112 return every_owner
OLDNEW
« no previous file with comments | « no previous file | tests/filesystem_mock.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698