OLD | NEW |
---|---|
(Empty) | |
1 import posixpath | |
not at google - send to devlin
2014/08/08 14:42:27
copyright
| |
2 | |
3 from data_source import DataSource | |
4 from extensions_paths import BROWSER_API_PATHS | |
5 from future import Future | |
6 | |
7 | |
8 _COMMENT_START_MARKER = '#' | |
9 _OWNERS = 'OWNERS' | |
10 | |
11 | |
12 def _ParseOwnersFile(content): | |
13 '''Returns a tuple (owners, notes), where | |
14 |owners| is a list of owners in |content|, | |
15 |notes| is a string formed from the comments in |content|. | |
16 ''' | |
17 owners = [] | |
18 notes = [] | |
19 for line in content.splitlines(): | |
20 # TODO(ahernandez): Don't ignore per-file. | |
21 if line.startswith('per-file') or line == '': | |
22 continue | |
23 if line.startswith(_COMMENT_START_MARKER): | |
24 notes.append(line[len(_COMMENT_START_MARKER):].lstrip()) | |
25 else: | |
26 owners.append(line) | |
27 return owners, ' '.join(notes) | |
28 | |
29 | |
30 class OwnersDataSource(DataSource): | |
31 def __init__(self, server_instance, _): | |
32 self._host_fs = server_instance.host_file_system_provider.GetTrunk() | |
33 self._owners_fs = server_instance.compiled_fs_factory.ForUnicode( | |
34 self._host_fs) | |
35 | |
36 def _CollectOwnersData(self): | |
37 '''Walks through the file system, collecting owners data from | |
38 API directories. | |
39 ''' | |
40 api_owners = [] | |
41 for root in BROWSER_API_PATHS: | |
42 for base, dirs, files in self._host_fs.Walk(root): | |
43 if base == root: | |
44 continue | |
45 if _OWNERS in files: | |
not at google - send to devlin
2014/08/08 14:42:27
we should only need to check 1 deep, not Walk over
| |
46 owners, notes = _ParseOwnersFile(self._owners_fs.GetFromFile( | |
47 posixpath.join(root, base, _OWNERS)).Get()) | |
48 api_owners.append({ | |
not at google - send to devlin
2014/08/08 14:45:20
ooh another idea - TODO for now because I don't kn
| |
49 'api_name': base, | |
50 'owners': ', '.join(owners), | |
51 'notes': notes | |
52 }) | |
53 # There is only one OWNERS file per directory. | |
54 continue | |
55 return api_owners | |
not at google - send to devlin
2014/08/08 14:42:27
we need to future-ise this.
| |
56 | |
57 def get(self, key): | |
58 return { | |
59 'apis': self._CollectOwnersData() | |
60 }.get(key) | |
61 | |
62 def Cron(self): | |
63 return Future(value=()) | |
OLD | NEW |