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

Unified Diff: chrome/common/extensions/docs/server2/owners_data_source.py

Issue 453713002: Docserver: Generate a table of extension/app API owners (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
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..9444321d89b7ab49d7e6c47a54cafcd218d05c66
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/owners_data_source.py
@@ -0,0 +1,88 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from operator import itemgetter
+import posixpath
+
+from data_source import DataSource
+from extensions_paths import BROWSER_API_PATHS, BROWSER_CHROME_EXTENSIONS
+from file_system import FileNotFoundError
+from path_util import IsDirectory
+from url_constants import CODEREVIEW_SERVER
+
+
+_COMMENT_START_MARKER = '#'
+_NO_OWNER = '<span class="warning">No owner.</span>'
+_OWNERS = 'OWNERS'
+_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
+
+
+def _ParseOwnersFile(content):
+ '''Returns a tuple (owners, notes), where
+ |owners| is a string fromed from the owners in |content|,
+ |notes| is a string formed from the comments in |content|.
+ '''
+ if content is None:
+ return _NO_OWNER, 'See core extensions owners.'
+ owners = []
+ notes = []
+ for line in content.splitlines():
+ # TODO(ahernandez): Don't ignore per-file.
+ if line == '':
+ continue
+ if line.startswith(_COMMENT_START_MARKER):
+ notes.append(line[len(_COMMENT_START_MARKER):].lstrip())
+ else:
+ owners.append(line)
+ 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
+ for owner in owners]), ' '.join(notes)
+
+
+class OwnersDataSource(DataSource):
+ def __init__(self, server_instance, _):
+ self._host_fs = server_instance.host_file_system_provider.GetTrunk()
+ 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
+
+ def _CollectOwnersData(self):
+ '''Walks through the file system, collecting owners data from
+ API directories.
+ '''
+ def collect(api_owners):
+ if api_owners is not None:
+ return api_owners
+ api_owners = []
+ for root in BROWSER_API_PATHS:
+ for file_ in self._host_fs.ReadSingle(root).Get():
not at google - send to devlin 2014/08/14 00:05:05 Then()
+ if not IsDirectory(file_):
+ continue
+ owners_file = posixpath.join(root, file_, _OWNERS)
+ content = self._host_fs.Read((owners_file,),
+ skip_not_found=True).Get()
not at google - send to devlin 2014/08/14 00:05:05 Then()
+ owners, notes = _ParseOwnersFile(content.get(owners_file, None))
+ api_owners.append({
+ 'apiName': file_[:-1],
+ 'owners': owners,
+ 'notes': notes
+ })
+ # Add an entry for the core extensions/apps owners.
+ extensions_owners = self._host_fs.ReadSingle(
+ 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
+ owners, notes = _ParseOwnersFile(extensions_owners)
+ api_owners.append({
+ 'apiName': 'Core Extensions/Apps Owners',
+ 'owners': owners,
+ 'notes': notes
+ })
+ api_owners.sort(key=itemgetter('apiName'))
+ self._cache.Set('api_owners', api_owners)
+ return api_owners
+ return self._cache.Get('api_owners').Then(collect)
+
+ def get(self, key):
+ return {
+ 'apis': self._CollectOwnersData()
+ }.get(key).Get()
+
+ def Cron(self):
+ return self._CollectOwnersData()

Powered by Google App Engine
This is Rietveld 408576698