| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 | 9 |
| 10 from extensions_paths import EXAMPLES | 10 from extensions_paths import EXAMPLES |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 self._base_path = base_path | 53 self._base_path = base_path |
| 54 self._platform = platform | 54 self._platform = platform |
| 55 | 55 |
| 56 def GetCache(self): | 56 def GetCache(self): |
| 57 return self._samples_cache | 57 return self._samples_cache |
| 58 | 58 |
| 59 def FilterSamples(self, api_name): | 59 def FilterSamples(self, api_name): |
| 60 '''Fetches and filters the list of samples for this platform, returning | 60 '''Fetches and filters the list of samples for this platform, returning |
| 61 only the samples that use the API |api_name|. | 61 only the samples that use the API |api_name|. |
| 62 ''' | 62 ''' |
| 63 samples_list = self._samples_cache.GetFromFileListing( | 63 try: |
| 64 '' if self._platform == 'apps' else EXAMPLES).Get() | 64 # TODO(rockot): This cache is probably not working as intended, since |
| 65 # it can still lead to underlying filesystem (e.g. gitiles) access |
| 66 # while processing live requests. Because this can fail, we at least |
| 67 # trap and log exceptions to prevent 500s from being thrown. |
| 68 samples_list = self._samples_cache.GetFromFileListing( |
| 69 '' if self._platform == 'apps' else EXAMPLES).Get() |
| 70 except Exception as e: |
| 71 logging.warning('Unable to get samples listing. Skipping.') |
| 72 samples_list = [] |
| 73 |
| 65 return [sample for sample in samples_list if any( | 74 return [sample for sample in samples_list if any( |
| 66 call['name'].startswith(api_name + '.') | 75 call['name'].startswith(api_name + '.') |
| 67 for call in sample['api_calls'])] | 76 for call in sample['api_calls'])] |
| 68 | 77 |
| 69 def _GetDataFromManifest(self, path, file_system): | 78 def _GetDataFromManifest(self, path, file_system): |
| 70 manifest = self._text_cache.GetFromFile(path + '/manifest.json').Get() | 79 manifest = self._text_cache.GetFromFile(path + '/manifest.json').Get() |
| 71 try: | 80 try: |
| 72 manifest_json = json.loads(json_comment_eater.Nom(manifest)) | 81 manifest_json = json.loads(json_comment_eater.Nom(manifest)) |
| 73 except ValueError as e: | 82 except ValueError as e: |
| 74 logging.error('Error parsing manifest.json for %s: %s' % (path, e)) | 83 logging.error('Error parsing manifest.json for %s: %s' % (path, e)) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 manifest_data.update({ | 170 manifest_data.update({ |
| 162 'icon': icon_path, | 171 'icon': icon_path, |
| 163 'download_url': download_url, | 172 'download_url': download_url, |
| 164 'url': url, | 173 'url': url, |
| 165 'files': [f.replace(sample_path + '/', '') for f in sample_files], | 174 'files': [f.replace(sample_path + '/', '') for f in sample_files], |
| 166 'api_calls': api_calls | 175 'api_calls': api_calls |
| 167 }) | 176 }) |
| 168 samples_list.append(manifest_data) | 177 samples_list.append(manifest_data) |
| 169 | 178 |
| 170 return samples_list | 179 return samples_list |
| OLD | NEW |