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

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

Issue 151883009: Docserver: Make MockFileSystem not iterate over the entire file system as part (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: yoz and then some Created 6 years, 10 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 json 5 import json
6 import logging 6 import logging
7 import posixpath 7 import posixpath
8 import re 8 import re
9 import traceback 9 import traceback
10 10
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 '''Fetches and filters the list of samples specified by |key|, returning 204 '''Fetches and filters the list of samples specified by |key|, returning
205 only the samples that use the API |api_name|. |key| is either 'apps' or 205 only the samples that use the API |api_name|. |key| is either 'apps' or
206 'extensions'. 206 'extensions'.
207 ''' 207 '''
208 return [sample for sample in self.get(key) if any( 208 return [sample for sample in self.get(key) if any(
209 call['name'].startswith(api_name + '.') 209 call['name'].startswith(api_name + '.')
210 for call in sample['api_calls'])] 210 for call in sample['api_calls'])]
211 211
212 def _CreateSamplesDict(self, key): 212 def _CreateSamplesDict(self, key):
213 if key == 'apps': 213 if key == 'apps':
214 samples_list = self._apps_cache.GetFromFileListing('/').Get() 214 samples_list = self._apps_cache.GetFromFileListing('').Get()
215 else: 215 else:
216 samples_list = self._extensions_cache.GetFromFileListing(EXAMPLES).Get() 216 samples_list = self._extensions_cache.GetFromFileListing(EXAMPLES).Get()
217 return_list = [] 217 return_list = []
218 for dict_ in samples_list: 218 for dict_ in samples_list:
219 name = dict_['name'] 219 name = dict_['name']
220 description = dict_['description'] 220 description = dict_['description']
221 if description is None: 221 if description is None:
222 description = '' 222 description = ''
223 if name.startswith('__MSG_') or description.startswith('__MSG_'): 223 if name.startswith('__MSG_') or description.startswith('__MSG_'):
224 try: 224 try:
(...skipping 18 matching lines...) Expand all
243 else: 243 else:
244 dict_['id'] = self._GetSampleId(name) 244 dict_['id'] = self._GetSampleId(name)
245 return_list.append(dict_) 245 return_list.append(dict_)
246 return return_list 246 return return_list
247 247
248 def get(self, key): 248 def get(self, key):
249 return { 249 return {
250 'apps': lambda: self._CreateSamplesDict('apps'), 250 'apps': lambda: self._CreateSamplesDict('apps'),
251 'extensions': lambda: self._CreateSamplesDict('extensions') 251 'extensions': lambda: self._CreateSamplesDict('extensions')
252 }.get(key, lambda: {})() 252 }.get(key, lambda: {})()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698