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

Side by Side Diff: chrome/common/extensions/docs/server2/api_list_data_source.py

Issue 10815042: Extensions Docs Server: api_index.html, experimental.html (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2012 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 import os
6
7 import third_party.json_schema_compiler.model as model
8
9 class APIListDataSource(object):
10 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs
11 that are used in the api_index.html and experimental.html pages.
12 """
13 def __init__(self, cache_builder, file_system, api_path, public_path):
14 self._cache = cache_builder.build(self._ListAPIs)
15 self._file_system = file_system
16 self._api_path = api_path + '/'
17 self._public_path = public_path + '/'
18
19 def _ListAPIs(self, apis):
20 api_names = [os.path.splitext(name)[0] for name in apis]
not at google - send to devlin 2012/07/23 12:40:24 this is only used for lookup, so make it a set? a
cduvall 2012/07/23 20:38:19 Done.
21 template_names = [os.path.splitext(name)[0] for name in
22 self._file_system.Read(
not at google - send to devlin 2012/07/23 12:40:24 Use that fancy new ReadSingle method? (or add it
23 [self._public_path]).Get()[self._public_path]]
24 unix_template_names = [model.UnixName(name) for name in template_names]
25 experimental_names = []
26 # Go through the template names, and remove all names not found in the api
27 # folder from the list. Add all experimental APIs to a separate list.
28 for name, i in zip(template_names, range(len(template_names))):
not at google - send to devlin 2012/07/23 12:40:24 Perhaps for i, template_name in enumerate(templat
cduvall 2012/07/23 20:38:19 Done.
29 if unix_template_names[i] not in api_names:
30 template_names.remove(name)
not at google - send to devlin 2012/07/23 12:40:24 removing stuff is O(n). Instead, add to a list lik
cduvall 2012/07/23 20:38:19 Done.
31 elif unix_template_names[i].startswith('experimental'):
32 template_names.remove(name)
33 experimental_names.append(name)
34 return {
35 'chrome': sorted([name.replace('_', '.') for name in template_names]),
36 'experimental': sorted([name.replace('_', '.') for name in
37 experimental_names])
not at google - send to devlin 2012/07/23 12:40:24 similar comment as above, list comp "for foo in ba
cduvall 2012/07/23 20:38:19 Done.
38 }
39
40 def __getitem__(self, key):
41 return self.get(key)
42
43 def get(self, key):
44 try:
45 return self._cache.GetFromFile(self._api_path)
not at google - send to devlin 2012/07/23 12:40:24 if you added [key] at the end of here then you cou
cduvall 2012/07/23 20:38:19 Done.
46 except Exception as e:
47 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698