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 json | 5 import json |
6 import logging | 6 import logging |
7 import re | 7 import re |
8 | 8 |
9 DEFAULT_ICON_PATH = '/static/images/sample-default-icon.png' | 9 DEFAULT_ICON_PATH = '/images/sample-default-icon.png' |
10 | 10 |
11 class SamplesDataSource(object): | 11 class SamplesDataSource(object): |
12 """Constructs a list of samples and their respective files and api calls. | 12 """Constructs a list of samples and their respective files and api calls. |
13 """ | 13 """ |
14 | 14 |
15 class Factory(object): | 15 class Factory(object): |
16 """A factory to create SamplesDataSource instances bound to individual | 16 """A factory to create SamplesDataSource instances bound to individual |
17 Requests. | 17 Requests. |
18 """ | 18 """ |
19 def __init__(self, file_system, cache_builder, samples_path): | 19 def __init__(self, branch, file_system, cache_builder, samples_path): |
| 20 self._static_path = ((('/' + branch) if branch != 'local' else '') + |
| 21 '/static') |
20 self._file_system = file_system | 22 self._file_system = file_system |
21 self._cache = cache_builder.build(self._MakeSamplesList) | 23 self._cache = cache_builder.build(self._MakeSamplesList) |
22 self._samples_path = samples_path | 24 self._samples_path = samples_path |
23 | 25 |
24 def Create(self, request): | 26 def Create(self, request): |
25 """Returns a new SamplesDataSource bound to |request|. | 27 """Returns a new SamplesDataSource bound to |request|. |
26 """ | 28 """ |
27 return SamplesDataSource(self._cache, | 29 return SamplesDataSource(self._cache, |
28 self._samples_path, | 30 self._samples_path, |
29 request) | 31 request) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 'link': self._MakeApiLink('event', item) | 86 'link': self._MakeApiLink('event', item) |
85 }) | 87 }) |
86 else: | 88 else: |
87 api_calls.append({ | 89 api_calls.append({ |
88 'name': item, | 90 'name': item, |
89 'link': self._MakeApiLink('method', item) | 91 'link': self._MakeApiLink('method', item) |
90 }) | 92 }) |
91 l10n_data = self._GetDataFromManifest(sample_path) | 93 l10n_data = self._GetDataFromManifest(sample_path) |
92 sample_base_path = sample_path.split('/', 1)[1] | 94 sample_base_path = sample_path.split('/', 1)[1] |
93 if l10n_data['icon'] is None: | 95 if l10n_data['icon'] is None: |
94 icon_path = DEFAULT_ICON_PATH | 96 icon_path = self._static_path + DEFAULT_ICON_PATH |
95 else: | 97 else: |
96 icon_path = sample_base_path + '/' + l10n_data['icon'] | 98 icon_path = sample_base_path + '/' + l10n_data['icon'] |
97 l10n_data.update({ | 99 l10n_data.update({ |
98 'icon': icon_path, | 100 'icon': icon_path, |
99 'path': sample_base_path, | 101 'path': sample_base_path, |
100 'files': [f.replace(sample_path + '/', '') for f in sample_files], | 102 'files': [f.replace(sample_path + '/', '') for f in sample_files], |
101 'api_calls': api_calls | 103 'api_calls': api_calls |
102 }) | 104 }) |
103 samples_list.append(l10n_data) | 105 samples_list.append(l10n_data) |
104 | 106 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 sample_data['name'] = locale_data[name_key]['message'] | 142 sample_data['name'] = locale_data[name_key]['message'] |
141 sample_data['description'] = locale_data[description_key]['message'] | 143 sample_data['description'] = locale_data[description_key]['message'] |
142 except Exception as e: | 144 except Exception as e: |
143 logging.error(e) | 145 logging.error(e) |
144 # Revert the sample to the original dict. | 146 # Revert the sample to the original dict. |
145 sample_data = dict_ | 147 sample_data = dict_ |
146 return_list.append(sample_data) | 148 return_list.append(sample_data) |
147 else: | 149 else: |
148 return_list.append(dict_) | 150 return_list.append(dict_) |
149 return return_list | 151 return return_list |
OLD | NEW |