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

Side by Side 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: Simpler logic 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 unified diff | Download patch
OLDNEW
(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, Future
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.'
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
45 def _CreateAPIEntry(self, api_name, owners_file):
46 '''Creates a dict with owners information for an API, specified
47 by |owners_file|.
48 '''
49 def create_entry(content):
50 owners, notes = _ParseOwnersFile(content.get(owners_file, None))
51 return {
52 'apiName': api_name,
53 'owners': owners,
54 'notes': notes
55 }
56 return self._host_fs.Read((owners_file,), skip_not_found=True).Then(
ahernandez 2014/08/14 22:17:18 This call is what gets run during the second cron
not at google - send to devlin 2014/08/14 22:32:12 I wonder if it has something to do with the skip_n
57 create_entry)
58
59 def _CollectOwnersData(self):
60 '''Walks through the file system, collecting owners data from
61 API directories.
62 '''
63 def collect(api_owners):
64 if api_owners is not None:
65 return api_owners
66 api_owners = []
67 for root in BROWSER_API_PATHS:
68 for base, dirs, _ in self._host_fs.Walk(root, depth=1):
69 for dir_ in dirs:
70 owners_file = posixpath.join(root, base, dir_, _OWNERS)
71 api_owners.append(self._CreateAPIEntry(dir_[:-1], owners_file))
72 # Add an entry for the core extensions/apps owners.
73 owners_file = posixpath.join(BROWSER_CHROME_EXTENSIONS, _OWNERS)
74 api_owners.append(self._CreateAPIEntry('Core Extensions/Apps Owners',
75 owners_file))
76 def sort(api_owners):
77 api_owners.sort(key=itemgetter('apiName'))
78 self._cache.Set('api_owners', api_owners)
79 return api_owners
80 api_owners_future = All(api_owners).Then(sort)
81 return api_owners_future
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()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698