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

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

Issue 23526077: [DocServer] Fixed Sample Links (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed kalman's feedback Created 7 years, 3 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
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 hashlib 5 import hashlib
6 import json 6 import json
7 import logging 7 import logging
8 import re 8 import re
9 9
10 from compiled_file_system import CompiledFileSystem 10 from compiled_file_system import CompiledFileSystem
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 icon_base = sample_base_path 144 icon_base = sample_base_path
145 download_url = sample_base_path + '.zip' 145 download_url = sample_base_path + '.zip'
146 146
147 manifest_data = self._GetDataFromManifest(sample_path, file_system) 147 manifest_data = self._GetDataFromManifest(sample_path, file_system)
148 if manifest_data['icon'] is None: 148 if manifest_data['icon'] is None:
149 icon_path = '%s/static/%s' % (self._base_path, DEFAULT_ICON_PATH) 149 icon_path = '%s/static/%s' % (self._base_path, DEFAULT_ICON_PATH)
150 else: 150 else:
151 icon_path = '%s/%s' % (icon_base, manifest_data['icon']) 151 icon_path = '%s/%s' % (icon_base, manifest_data['icon'])
152 manifest_data.update({ 152 manifest_data.update({
153 'icon': icon_path, 153 'icon': icon_path,
154 'id': hashlib.md5(url).hexdigest(),
155 'download_url': download_url, 154 'download_url': download_url,
156 'url': url, 155 'url': url,
157 'files': [f.replace(sample_path + '/', '') for f in sample_files], 156 'files': [f.replace(sample_path + '/', '') for f in sample_files],
158 'api_calls': api_calls 157 'api_calls': api_calls
159 }) 158 })
160 samples_list.append(manifest_data) 159 samples_list.append(manifest_data)
161 160
162 return samples_list 161 return samples_list
163 162
164 def __init__(self, 163 def __init__(self,
165 extensions_cache, 164 extensions_cache,
166 apps_cache, 165 apps_cache,
167 extension_samples_path, 166 extension_samples_path,
168 base_path, 167 base_path,
169 request): 168 request):
170 self._extensions_cache = extensions_cache 169 self._extensions_cache = extensions_cache
171 self._apps_cache = apps_cache 170 self._apps_cache = apps_cache
172 self._extension_samples_path = extension_samples_path 171 self._extension_samples_path = extension_samples_path
173 self._base_path = base_path 172 self._base_path = base_path
174 self._request = request 173 self._request = request
175 174
175 def _GetSampleId(self, sample_name):
176 return sample_name.lower().replace(' ', '-')
177
176 def _GetAcceptedLanguages(self): 178 def _GetAcceptedLanguages(self):
177 accept_language = self._request.headers.get('Accept-Language', None) 179 accept_language = self._request.headers.get('Accept-Language', None)
178 if accept_language is None: 180 if accept_language is None:
179 return [] 181 return []
180 return [lang_with_q.split(';')[0].strip() 182 return [lang_with_q.split(';')[0].strip()
181 for lang_with_q in accept_language.split(',')] 183 for lang_with_q in accept_language.split(',')]
182 184
183 def FilterSamples(self, key, api_name): 185 def FilterSamples(self, key, api_name):
184 '''Fetches and filters the list of samples specified by |key|, returning 186 '''Fetches and filters the list of samples specified by |key|, returning
185 only the samples that use the API |api_name|. |key| is either 'apps' or 187 only the samples that use the API |api_name|. |key| is either 'apps' or
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 name_key = name[len('__MSG_'):-len('__')] 222 name_key = name[len('__MSG_'):-len('__')]
221 description_key = description[len('__MSG_'):-len('__')] 223 description_key = description[len('__MSG_'):-len('__')]
222 locale = sample_data['default_locale'] 224 locale = sample_data['default_locale']
223 for lang in self._GetAcceptedLanguages(): 225 for lang in self._GetAcceptedLanguages():
224 if lang in sample_data['locales']: 226 if lang in sample_data['locales']:
225 locale = lang 227 locale = lang
226 break 228 break
227 locale_data = sample_data['locales'][locale] 229 locale_data = sample_data['locales'][locale]
228 sample_data['name'] = locale_data[name_key]['message'] 230 sample_data['name'] = locale_data[name_key]['message']
229 sample_data['description'] = locale_data[description_key]['message'] 231 sample_data['description'] = locale_data[description_key]['message']
232 sample_data['id'] = self._GetSampleId(sample_data['name'])
230 except Exception as e: 233 except Exception as e:
231 logging.error(e) 234 logging.error(e)
not at google - send to devlin 2013/09/23 15:59:51 incremental cleanup: except: logging.error(trac
François Beaufort 2013/09/24 09:24:49 Done.
232 # Revert the sample to the original dict. 235 # Revert the sample to the original dict.
233 sample_data = dict_ 236 sample_data = dict_
234 return_list.append(sample_data) 237 return_list.append(sample_data)
235 else: 238 else:
239 dict_['id'] = self._GetSampleId(name)
236 return_list.append(dict_) 240 return_list.append(dict_)
237 return return_list 241 return return_list
238 242
239 def get(self, key): 243 def get(self, key):
240 return { 244 return {
241 'apps': lambda: self._CreateSamplesDict('apps'), 245 'apps': lambda: self._CreateSamplesDict('apps'),
242 'extensions': lambda: self._CreateSamplesDict('extensions') 246 'extensions': lambda: self._CreateSamplesDict('extensions')
243 }.get(key, lambda: {})() 247 }.get(key, lambda: {})()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698