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 extensions_paths import BROWSER_API_PATHS, BROWSER_CHROME_EXTENSIONS | |
| 10 from file_system import FileNotFoundError | |
| 11 from path_util import IsDirectory | |
| 12 from url_constants import CODEREVIEW_SERVER | |
| 13 | |
| 14 | |
| 15 _COMMENT_START_MARKER = '#' | |
| 16 _NO_OWNER = '<span class="warning">No owner.</span>' | |
| 17 _OWNERS = 'OWNERS' | |
| 18 _OWNER_BASE_URL = '<a href=' + CODEREVIEW_SERVER + '/user/%s>%s</a>' | |
|
not at google - send to devlin
2014/08/14 00:05:05
Don't generate HTML here, generate enough data in
| |
| 19 | |
| 20 | |
| 21 def _ParseOwnersFile(content): | |
| 22 '''Returns a tuple (owners, notes), where | |
| 23 |owners| is a string fromed from the owners in |content|, | |
| 24 |notes| is a string formed from the comments in |content|. | |
| 25 ''' | |
| 26 if content is None: | |
| 27 return _NO_OWNER, 'See core extensions owners.' | |
| 28 owners = [] | |
| 29 notes = [] | |
| 30 for line in content.splitlines(): | |
| 31 # TODO(ahernandez): Don't ignore per-file. | |
| 32 if line == '': | |
| 33 continue | |
| 34 if line.startswith(_COMMENT_START_MARKER): | |
| 35 notes.append(line[len(_COMMENT_START_MARKER):].lstrip()) | |
| 36 else: | |
| 37 owners.append(line) | |
| 38 return ', '.join([_OWNER_BASE_URL % (owner, owner[:owner.find('@')]) | |
|
not at google - send to devlin
2014/08/14 00:05:05
You should be able to join() a generator (i.e. no
| |
| 39 for owner in owners]), ' '.join(notes) | |
| 40 | |
| 41 | |
| 42 class OwnersDataSource(DataSource): | |
| 43 def __init__(self, server_instance, _): | |
| 44 self._host_fs = server_instance.host_file_system_provider.GetTrunk() | |
| 45 self._cache = server_instance.object_store_creator.Create(OwnersDataSource) | |
|
ahernandez
2014/08/14 21:48:21
The reason this is failing the cron servlet is tha
not at google - send to devlin
2014/08/14 22:02:10
Hm, those object stores are supposed to stay aroun
ahernandez
2014/08/14 22:09:16
I already have it implemented with Walk (I haven't
| |
| 46 | |
| 47 def _CollectOwnersData(self): | |
| 48 '''Walks through the file system, collecting owners data from | |
| 49 API directories. | |
| 50 ''' | |
| 51 def collect(api_owners): | |
| 52 if api_owners is not None: | |
| 53 return api_owners | |
| 54 api_owners = [] | |
| 55 for root in BROWSER_API_PATHS: | |
| 56 for file_ in self._host_fs.ReadSingle(root).Get(): | |
|
not at google - send to devlin
2014/08/14 00:05:05
Then()
| |
| 57 if not IsDirectory(file_): | |
| 58 continue | |
| 59 owners_file = posixpath.join(root, file_, _OWNERS) | |
| 60 content = self._host_fs.Read((owners_file,), | |
| 61 skip_not_found=True).Get() | |
|
not at google - send to devlin
2014/08/14 00:05:05
Then()
| |
| 62 owners, notes = _ParseOwnersFile(content.get(owners_file, None)) | |
| 63 api_owners.append({ | |
| 64 'apiName': file_[:-1], | |
| 65 'owners': owners, | |
| 66 'notes': notes | |
| 67 }) | |
| 68 # Add an entry for the core extensions/apps owners. | |
| 69 extensions_owners = self._host_fs.ReadSingle( | |
| 70 posixpath.join(BROWSER_CHROME_EXTENSIONS, _OWNERS)).Get() | |
|
not at google - send to devlin
2014/08/14 00:05:05
Then()
And splitting up these entirely serial met
| |
| 71 owners, notes = _ParseOwnersFile(extensions_owners) | |
| 72 api_owners.append({ | |
| 73 'apiName': 'Core Extensions/Apps Owners', | |
| 74 'owners': owners, | |
| 75 'notes': notes | |
| 76 }) | |
| 77 api_owners.sort(key=itemgetter('apiName')) | |
| 78 self._cache.Set('api_owners', api_owners) | |
| 79 return api_owners | |
| 80 return self._cache.Get('api_owners').Then(collect) | |
| 81 | |
| 82 def get(self, key): | |
| 83 return { | |
| 84 'apis': self._CollectOwnersData() | |
| 85 }.get(key).Get() | |
| 86 | |
| 87 def Cron(self): | |
| 88 return self._CollectOwnersData() | |
| OLD | NEW |