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

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: 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 random
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
13 from path_util import Join, Split
14
15
16 _COMMENT_START_MARKER = '#'
17 _CORE_OWNERS = 'Core Extensions/Apps Owners'
18 _OWNERS = 'OWNERS'
19
20
21 def _ParseOwnersFile(content, randomize):
not at google - send to devlin 2014/08/21 21:39:58 This method should probably be non-private with a
22 '''Returns a tuple (owners, notes), where
23 |owners| is a list of dicts formed from the owners in |content|,
24 |notes| is a string formed from the comments in |content|.
25 '''
26 if content is None:
27 return [], 'Use one of the ' + _CORE_OWNERS + '.'
28 owners = []
29 notes = []
30 for line in content.splitlines():
31 if line == '':
32 continue
33 if line.startswith(_COMMENT_START_MARKER):
34 notes.append(line[len(_COMMENT_START_MARKER):].lstrip())
35 else:
36 # TODO(ahernandez): Mark owners no longer on the project.
37 owners.append({'email': line, 'username': line[:line.find('@')]})
38 # Randomize the list so owners toward the front of the list aren't
39 # diproportionately inundated with reviews.
40 if randomize:
41 random.shuffle(owners)
not at google - send to devlin 2014/08/21 21:39:58 Aww awesome :)
42 MarkLast(owners)
43 return owners, '\n'.join(notes)
44
45
46 class OwnersDataSource(DataSource):
47 def __init__(self, server_instance, _, randomize=True):
48 self._host_fs = server_instance.host_file_system_provider.GetTrunk()
49 self._cache = server_instance.object_store_creator.Create(OwnersDataSource)
50 self._owners_fs = server_instance.compiled_fs_factory.Create(
51 self._host_fs, self._CreateAPIEntry, OwnersDataSource)
52 self._randomize = randomize
53
54 def _CreateAPIEntry(self, path, content):
55 '''Creates a dict with owners information for an API, specified
56 by |owners_file|.
57 '''
58 owners, notes = _ParseOwnersFile(content, self._randomize)
59 return {
60 'apiName': Split(path)[-2][:-1],
61 'owners': owners,
62 'notes': notes
63 }
64
65 def _CollectOwnersData(self):
66 '''Walks through the file system, collecting owners data from
67 API directories.
68 '''
69 def collect(api_owners):
70 if api_owners is not None:
71 return api_owners
not at google - send to devlin 2014/08/21 21:39:58 Nit: newline after this. The method is fairly long
72 api_owners = []
not at google - send to devlin 2014/08/21 21:39:58 Comment before |api_owners|: Get API owners from e
73 for root in BROWSER_API_PATHS:
74 for base, dirs, _ in self._host_fs.Walk(root, depth=1):
75 for dir_ in dirs:
76 owners_file = Join(root, base, dir_, _OWNERS)
77 api_owners.append(self._owners_fs.GetFromFile(owners_file, True))
not at google - send to devlin 2014/08/21 21:39:58 skip_not_found=True
78
not at google - send to devlin 2014/08/26 01:15:23 Found trailing spaces here as well.
79 def fix_core_owners(entry):
not at google - send to devlin 2014/08/21 21:39:58 Nit: declare this underneath the "Add an entry..."
80 entry['apiName'] = _CORE_OWNERS
81 return entry
82 # Add an entry for the core extensions/apps owners.
83 owners_file = Join(BROWSER_CHROME_EXTENSIONS, _OWNERS)
84 api_owners.append(self._owners_fs.GetFromFile(owners_file).Then(
85 fix_core_owners))
86 def sort_and_cache(api_owners):
87 api_owners.sort(key=itemgetter('apiName'))
88 self._cache.Set('api_owners', api_owners)
89 return api_owners
90 return All(api_owners).Then(sort_and_cache)
91 return self._cache.Get('api_owners').Then(collect)
92
93 def get(self, key):
94 return {
95 'apis': self._CollectOwnersData()
96 }.get(key).Get()
97
98 def Cron(self):
99 return self._CollectOwnersData()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698