| OLD | NEW |
| 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 hashlib | 5 import hashlib |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 import posixpath | 8 import posixpath |
| 9 import re | 9 import re |
| 10 import traceback | 10 import traceback |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 if accept_language is None: | 184 if accept_language is None: |
| 185 return [] | 185 return [] |
| 186 return [lang_with_q.split(';')[0].strip() | 186 return [lang_with_q.split(';')[0].strip() |
| 187 for lang_with_q in accept_language.split(',')] | 187 for lang_with_q in accept_language.split(',')] |
| 188 | 188 |
| 189 def FilterSamples(self, key, api_name): | 189 def FilterSamples(self, key, api_name): |
| 190 '''Fetches and filters the list of samples specified by |key|, returning | 190 '''Fetches and filters the list of samples specified by |key|, returning |
| 191 only the samples that use the API |api_name|. |key| is either 'apps' or | 191 only the samples that use the API |api_name|. |key| is either 'apps' or |
| 192 'extensions'. | 192 'extensions'. |
| 193 ''' | 193 ''' |
| 194 api_search = api_name.replace('.', '_') + '_' | 194 return [sample for sample in self.get(key) if any( |
| 195 samples_list = [] | 195 call['name'].startswith(api_name + '.') |
| 196 try: | 196 for call in sample['api_calls'])] |
| 197 for sample in self.get(key): | |
| 198 api_calls_unix = [model.UnixName(call['name']) | |
| 199 for call in sample['api_calls']] | |
| 200 for call in api_calls_unix: | |
| 201 if call.startswith(api_search): | |
| 202 samples_list.append(sample) | |
| 203 break | |
| 204 except NotImplementedError: | |
| 205 # If we're testing, the GithubFileSystem can't fetch samples. | |
| 206 # Bug: http://crbug.com/141910 | |
| 207 return [] | |
| 208 return samples_list | |
| 209 | 197 |
| 210 def _CreateSamplesDict(self, key): | 198 def _CreateSamplesDict(self, key): |
| 211 if key == 'apps': | 199 if key == 'apps': |
| 212 samples_list = self._apps_cache.GetFromFileListing('/').Get() | 200 samples_list = self._apps_cache.GetFromFileListing('/').Get() |
| 213 else: | 201 else: |
| 214 samples_list = self._extensions_cache.GetFromFileListing( | 202 samples_list = self._extensions_cache.GetFromFileListing( |
| 215 self._extension_samples_path + '/').Get() | 203 self._extension_samples_path + '/').Get() |
| 216 return_list = [] | 204 return_list = [] |
| 217 for dict_ in samples_list: | 205 for dict_ in samples_list: |
| 218 name = dict_['name'] | 206 name = dict_['name'] |
| (...skipping 23 matching lines...) Expand all Loading... |
| 242 else: | 230 else: |
| 243 dict_['id'] = self._GetSampleId(name) | 231 dict_['id'] = self._GetSampleId(name) |
| 244 return_list.append(dict_) | 232 return_list.append(dict_) |
| 245 return return_list | 233 return return_list |
| 246 | 234 |
| 247 def get(self, key): | 235 def get(self, key): |
| 248 return { | 236 return { |
| 249 'apps': lambda: self._CreateSamplesDict('apps'), | 237 'apps': lambda: self._CreateSamplesDict('apps'), |
| 250 'extensions': lambda: self._CreateSamplesDict('extensions') | 238 'extensions': lambda: self._CreateSamplesDict('extensions') |
| 251 }.get(key, lambda: {})() | 239 }.get(key, lambda: {})() |
| OLD | NEW |