Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 from operator import itemgetter | |
| 6 import posixpath | |
| 7 | |
| 8 from data_source import DataSource | |
| 9 from docs_server_utils import MarkLast | |
| 10 from extensions_paths import BROWSER_API_PATHS, BROWSER_CHROME_EXTENSIONS | |
| 11 from file_system import FileNotFoundError | |
| 12 from future import All | |
| 13 | |
| 14 | |
| 15 _COMMENT_START_MARKER = '#' | |
| 16 _OWNERS = 'OWNERS' | |
| 17 | |
| 18 | |
| 19 def _ParseOwnersFile(content): | |
| 20 '''Returns a tuple (owners, notes), where | |
| 21 |owners| is a list of dicts formed from the owners in |content|, | |
| 22 |notes| is a string formed from the comments in |content|. | |
| 23 ''' | |
| 24 if content is None: | |
| 25 return [], 'See core extensions owners.' | |
|
not at google - send to devlin
2014/08/15 15:45:51
Let's share a string with 'Core Extensions/Apps Ow
| |
| 26 owners = [] | |
| 27 notes = [] | |
| 28 for line in content.splitlines(): | |
| 29 if line == '': | |
| 30 continue | |
| 31 if line.startswith(_COMMENT_START_MARKER): | |
| 32 notes.append(line[len(_COMMENT_START_MARKER):].lstrip()) | |
| 33 else: | |
| 34 # TODO(ahernandez): Mark owners no longer on the project. | |
| 35 owners.append({'email': line, 'username': line[:line.find('@')]}) | |
| 36 MarkLast(owners) | |
| 37 return owners, ' '.join(notes) | |
| 38 | |
| 39 | |
| 40 class OwnersDataSource(DataSource): | |
| 41 def __init__(self, server_instance, _): | |
| 42 self._host_fs = server_instance.host_file_system_provider.GetTrunk() | |
| 43 self._cache = server_instance.object_store_creator.Create(OwnersDataSource) | |
| 44 self._owners_fs = server_instance.compiled_fs_factory.Create( | |
| 45 self._host_fs, self._CreateAPIEntry, OwnersDataSource) | |
| 46 | |
| 47 def _CreateAPIEntry(self, path, content): | |
|
not at google - send to devlin
2014/08/15 15:45:51
content is optional, so content=None.
not at google - send to devlin
2014/08/21 21:39:57
Oh, my bad. sorry.
| |
| 48 '''Creates a dict with owners information for an API, specified | |
| 49 by |owners_file|. | |
| 50 ''' | |
| 51 owners, notes = _ParseOwnersFile(content) | |
| 52 return { | |
| 53 'apiName': posixpath.basename(posixpath.dirname(path)), | |
| 54 'owners': owners, | |
| 55 'notes': notes | |
| 56 } | |
| 57 | |
| 58 def _CollectOwnersData(self): | |
| 59 '''Walks through the file system, collecting owners data from | |
| 60 API directories. | |
| 61 ''' | |
| 62 def collect(api_owners): | |
| 63 if api_owners is not None: | |
| 64 return api_owners | |
| 65 api_owners = [] | |
| 66 for root in BROWSER_API_PATHS: | |
| 67 for base, dirs, _ in self._host_fs.Walk(root, depth=1): | |
| 68 for dir_ in dirs: | |
| 69 owners_file = posixpath.join(root, base, dir_, _OWNERS) | |
|
not at google - send to devlin
2014/08/15 15:45:51
For all of these posixpath calls, prefer using the
| |
| 70 if self._owners_fs.FileExists(owners_file).Get(): | |
|
not at google - send to devlin
2014/08/15 15:45:51
What happened to using .Then() everywhere?
I'm wo
| |
| 71 api_owners.append(self._owners_fs.GetFromFile(owners_file).Get()) | |
| 72 else: | |
| 73 api_owners.append(self._CreateAPIEntry(owners_file, None)) | |
| 74 # Add an entry for the core extensions/apps owners. | |
| 75 owners_file = posixpath.join(BROWSER_CHROME_EXTENSIONS, _OWNERS) | |
| 76 entry = self._owners_fs.GetFromFile(owners_file).Get() | |
|
not at google - send to devlin
2014/08/15 15:45:51
.Get() here as well.
| |
| 77 entry['apiName'] = 'Core Extensions/Apps Owners' | |
| 78 api_owners.append(entry) | |
| 79 api_owners.sort(key=itemgetter('apiName')) | |
| 80 self._cache.Set('api_owners', api_owners) | |
| 81 return api_owners | |
| 82 return self._cache.Get('api_owners').Then(collect) | |
| 83 | |
| 84 def get(self, key): | |
| 85 return { | |
| 86 'apis': self._CollectOwnersData() | |
| 87 }.get(key).Get() | |
| 88 | |
| 89 def Cron(self): | |
| 90 return self._CollectOwnersData() | |
| OLD | NEW |