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

Side by Side Diff: watchlists.py

Issue 126272: Add unit tests for watchlists (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years, 6 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 | « tests/watchlists_unittest.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Watchlists 6 """Watchlists
7 7
8 Watchlists is a mechanism that allow a developer (a "watcher") to watch over 8 Watchlists is a mechanism that allow a developer (a "watcher") to watch over
9 portions of code that he is interested in. A "watcher" will be cc-ed to 9 portions of code that he is interested in. A "watcher" will be cc-ed to
10 changes that modify that portion of code, thereby giving him an opportunity 10 changes that modify that portion of code, thereby giving him an opportunity
(...skipping 27 matching lines...) Expand all
38 _RULES_FILENAME = _RULES 38 _RULES_FILENAME = _RULES
39 _repo_root = None 39 _repo_root = None
40 _defns = {} # Definitions 40 _defns = {} # Definitions
41 _watchlists = {} # name to email mapping 41 _watchlists = {} # name to email mapping
42 42
43 def __init__(self, repo_root): 43 def __init__(self, repo_root):
44 self._repo_root = repo_root 44 self._repo_root = repo_root
45 self._LoadWatchlistRules() 45 self._LoadWatchlistRules()
46 46
47 def _GetRulesFilePath(self): 47 def _GetRulesFilePath(self):
48 """Returns path to WATCHLISTS file."""
48 return os.path.join(self._repo_root, self._RULES_FILENAME) 49 return os.path.join(self._repo_root, self._RULES_FILENAME)
49 50
50 def _HasWatchlistsFile(self): 51 def _HasWatchlistsFile(self):
51 """Determine if watchlists are available for this repo.""" 52 """Determine if watchlists are available for this repo."""
52 return os.path.exists(self._GetRulesFilePath()) 53 return os.path.exists(self._GetRulesFilePath())
53 54
55 def _ContentsOfWatchlistsFile(self):
56 """Read the WATCHLISTS file and return its contents."""
57 try:
58 watchlists_file = open(self._GetRulesFilePath())
59 contents = watchlists_file.read()
60 watchlists_file.close()
61 return contents
62 except IOError, e:
63 logging.error("Cannot read %s: %s" % (self._GetRulesFilePath(), e))
64 return ''
65
54 def _LoadWatchlistRules(self): 66 def _LoadWatchlistRules(self):
67 """Load watchlists from WATCHLISTS file. Does nothing if not present."""
55 if not self._HasWatchlistsFile(): 68 if not self._HasWatchlistsFile():
56 return 69 return
57 watchlists_file = open(self._GetRulesFilePath())
58 contents = watchlists_file.read()
59 watchlists_file.close()
60 70
71 contents = self._ContentsOfWatchlistsFile()
61 watchlists_data = None 72 watchlists_data = None
62 try: 73 try:
63 watchlists_data = eval(contents, {'__builtins__': None}, None) 74 watchlists_data = eval(contents, {'__builtins__': None}, None)
64 except SyntaxError, e: 75 except SyntaxError, e:
65 logging.error("Cannot parse %s. %s" % (self._GetRulesFilePath(), e)) 76 logging.error("Cannot parse %s. %s" % (self._GetRulesFilePath(), e))
66 return 77 return
67 78
68 defns = watchlists_data.get("WATCHLIST_DEFINITIONS") 79 defns = watchlists_data.get("WATCHLIST_DEFINITIONS")
69 if not defns: 80 if not defns:
70 logging.error("WATCHLIST_DEFINITIONS not defined in %s" % 81 logging.error("WATCHLIST_DEFINITIONS not defined in %s" %
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 print "Usage (from the base of repo):" 119 print "Usage (from the base of repo):"
109 print " %s [file-1] [file-2] ...." % argv[0] 120 print " %s [file-1] [file-2] ...." % argv[0]
110 return 1 121 return 1
111 wl = Watchlists(os.getcwd()) 122 wl = Watchlists(os.getcwd())
112 watchers = wl.GetWatchersForPaths(argv[1:]) 123 watchers = wl.GetWatchersForPaths(argv[1:])
113 print watchers 124 print watchers
114 125
115 126
116 if __name__ == '__main__': 127 if __name__ == '__main__':
117 main(sys.argv) 128 main(sys.argv)
OLDNEW
« no previous file with comments | « tests/watchlists_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698