Index: chrome/common/extensions/docs/server2/owners_data_source.py |
diff --git a/chrome/common/extensions/docs/server2/owners_data_source.py b/chrome/common/extensions/docs/server2/owners_data_source.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6247d57e9c92903383bc84cc1f925c06b4405460 |
--- /dev/null |
+++ b/chrome/common/extensions/docs/server2/owners_data_source.py |
@@ -0,0 +1,63 @@ |
+import posixpath |
not at google - send to devlin
2014/08/08 14:42:27
copyright
|
+ |
+from data_source import DataSource |
+from extensions_paths import BROWSER_API_PATHS |
+from future import Future |
+ |
+ |
+_COMMENT_START_MARKER = '#' |
+_OWNERS = 'OWNERS' |
+ |
+ |
+def _ParseOwnersFile(content): |
+ '''Returns a tuple (owners, notes), where |
+ |owners| is a list of owners in |content|, |
+ |notes| is a string formed from the comments in |content|. |
+ ''' |
+ owners = [] |
+ notes = [] |
+ for line in content.splitlines(): |
+ # TODO(ahernandez): Don't ignore per-file. |
+ if line.startswith('per-file') or line == '': |
+ continue |
+ if line.startswith(_COMMENT_START_MARKER): |
+ notes.append(line[len(_COMMENT_START_MARKER):].lstrip()) |
+ else: |
+ owners.append(line) |
+ return owners, ' '.join(notes) |
+ |
+ |
+class OwnersDataSource(DataSource): |
+ def __init__(self, server_instance, _): |
+ self._host_fs = server_instance.host_file_system_provider.GetTrunk() |
+ self._owners_fs = server_instance.compiled_fs_factory.ForUnicode( |
+ self._host_fs) |
+ |
+ def _CollectOwnersData(self): |
+ '''Walks through the file system, collecting owners data from |
+ API directories. |
+ ''' |
+ api_owners = [] |
+ for root in BROWSER_API_PATHS: |
+ for base, dirs, files in self._host_fs.Walk(root): |
+ if base == root: |
+ continue |
+ 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
|
+ owners, notes = _ParseOwnersFile(self._owners_fs.GetFromFile( |
+ posixpath.join(root, base, _OWNERS)).Get()) |
+ 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
|
+ 'api_name': base, |
+ 'owners': ', '.join(owners), |
+ 'notes': notes |
+ }) |
+ # There is only one OWNERS file per directory. |
+ continue |
+ return api_owners |
not at google - send to devlin
2014/08/08 14:42:27
we need to future-ise this.
|
+ |
+ def get(self, key): |
+ return { |
+ 'apis': self._CollectOwnersData() |
+ }.get(key) |
+ |
+ def Cron(self): |
+ return Future(value=()) |