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

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

Issue 10797039: Extensions Docs Server: devtools API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: console and audits are back 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
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 6
7 import third_party.json_schema_compiler.model as model 7 import third_party.json_schema_compiler.model as model
8 8
9 class APIListDataSource(object): 9 class APIListDataSource(object):
10 """ This class creates a list of chrome.* APIs and chrome.experimental.* APIs 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. 11 that are used in the api_index.html and experimental.html pages.
12 """ 12 """
13 def __init__(self, cache_builder, file_system, api_path, public_path): 13 def __init__(self, cache_builder, file_system, api_path, public_path):
14 self._cache = cache_builder.build(self._ListAPIs) 14 self._cache = cache_builder.build(self._ListAPIs)
15 self._file_system = file_system 15 self._file_system = file_system
16 self._api_path = api_path + '/' 16 self._api_path = api_path + '/'
17 self._public_path = public_path + '/' 17 self._public_path = public_path + '/'
18 18
19 def _SanitizeAPIName(self, name):
20 filename = os.path.splitext(name)[0][len(self._api_path):].replace('/', '_')
21 if 'experimental' in filename:
22 filename = 'experimental_' + filename.replace('experimental_', '')
23 return filename
not at google - send to devlin 2012/07/30 08:17:20 This will have to play well with things like - lin
cduvall 2012/07/31 18:41:45 This is not used for handling $refs, this is just
24
19 def _ListAPIs(self, apis): 25 def _ListAPIs(self, apis):
20 api_names = set(os.path.splitext(name)[0] for name in apis) 26 api_names = set(self._SanitizeAPIName(name) for name in apis)
21 public_templates = self._file_system.ReadSingle(self._public_path) 27 public_templates = self._file_system.ReadSingle(self._public_path)
22 template_names = [os.path.splitext(name)[0] for name in public_templates] 28 template_names = [os.path.splitext(name)[0] for name in public_templates]
23 experimental_apis = [] 29 experimental_apis = []
24 chrome_apis = [] 30 chrome_apis = []
25 for i, template_name in enumerate(template_names): 31 for i, template_name in enumerate(template_names):
26 if model.UnixName(template_name) in api_names: 32 if model.UnixName(template_name) in api_names:
27 if template_name.startswith('experimental'): 33 if template_name.startswith('experimental'):
28 experimental_apis.append({ 'name': template_name.replace('_', '.') }) 34 experimental_apis.append({ 'name': template_name.replace('_', '.') })
29 else: 35 else:
30 chrome_apis.append({ 'name': template_name.replace('_', '.') }) 36 chrome_apis.append({ 'name': template_name.replace('_', '.') })
31 chrome_apis[-1]['last'] = True 37 chrome_apis[-1]['last'] = True
32 experimental_apis[-1]['last'] = True 38 experimental_apis[-1]['last'] = True
33 return { 39 return {
34 'chrome': sorted(chrome_apis), 40 'chrome': sorted(chrome_apis),
35 'experimental': sorted(experimental_apis) 41 'experimental': sorted(experimental_apis)
36 } 42 }
37 43
38 def __getitem__(self, key): 44 def __getitem__(self, key):
39 return self.get(key) 45 return self.get(key)
40 46
41 def get(self, key): 47 def get(self, key):
42 try: 48 try:
43 return self._cache.GetFromFile(self._api_path)[key] 49 return self._cache.GetFromFileListing(self._api_path)[key]
44 except Exception as e: 50 except Exception as e:
45 return None 51 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698