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

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: mlg rebasing Created 6 years, 3 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 future import All
12 from path_util import Join, Split
13
14
15 _COMMENT_START_MARKER = '#'
16 _CORE_OWNERS = 'Core Extensions/Apps Owners'
17 _OWNERS = 'OWNERS'
18
19
20 # Public for testing.
21 def ParseOwnersFile(content, randomize):
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)
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 api_name = Split(path)[-2][:-1]
60 return {
61 'apiName': api_name,
62 'owners': owners,
63 'notes': notes,
64 'id': api_name
65 }
66
67 def _CollectOwnersData(self):
68 '''Walks through the file system, collecting owners data from
69 API directories.
70 '''
71 def collect(api_owners):
72 if api_owners is not None:
73 return api_owners
74
75 # Get API owners from every OWNERS file that exists.
76 api_owners = []
77 for root in BROWSER_API_PATHS:
78 for base, dirs, _ in self._host_fs.Walk(root, depth=1):
79 for dir_ in dirs:
80 owners_file = Join(root, base, dir_, _OWNERS)
81 api_owners.append(
82 self._owners_fs.GetFromFile(owners_file, skip_not_found=True))
83
84 # Add an entry for the core extensions/apps owners.
85 def fix_core_owners(entry):
86 entry['apiName'] = _CORE_OWNERS
87 entry['id'] = 'core'
88 return entry
89
90 owners_file = Join(BROWSER_CHROME_EXTENSIONS, _OWNERS)
91 api_owners.append(self._owners_fs.GetFromFile(owners_file).Then(
92 fix_core_owners))
93 def sort_and_cache(api_owners):
94 api_owners.sort(key=itemgetter('apiName'))
95 self._cache.Set('api_owners', api_owners)
96 return api_owners
97 return All(api_owners).Then(sort_and_cache)
98 return self._cache.Get('api_owners').Then(collect)
99
100 def get(self, key):
101 return {
102 'apis': self._CollectOwnersData()
103 }.get(key).Get()
104
105 def Cron(self):
106 return self._CollectOwnersData()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698