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

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

Issue 10835012: Extension Docs Server: Include a list of samples used in the api reference page. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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 json 5 import json
6 import logging 6 import logging
7 import re 7 import re
8 8
9 DEFAULT_ICON_PATH = '/images/sample-default-icon.png' 9 DEFAULT_ICON_PATH = '/images/sample-default-icon.png'
10 10
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 def _GetAcceptedLanguages(self): 114 def _GetAcceptedLanguages(self):
115 accept_language = self._request.headers.get('Accept-Language', None) 115 accept_language = self._request.headers.get('Accept-Language', None)
116 if accept_language is None: 116 if accept_language is None:
117 return [] 117 return []
118 return [lang_with_q.split(';')[0].strip() 118 return [lang_with_q.split(';')[0].strip()
119 for lang_with_q in accept_language.split(',')] 119 for lang_with_q in accept_language.split(',')]
120 120
121 def __getitem__(self, key): 121 def __getitem__(self, key):
122 return self.get(key) 122 return self.get(key)
123 123
124 def values(self):
125 return self.get('')
not at google - send to devlin 2012/08/01 10:09:19 call GetAll plz. Incidentally we should rename al
chebert 2012/08/01 18:04:33 The reason they are called get() and values() is t
not at google - send to devlin 2012/08/01 20:56:32 Ah cool. No problem.
126
124 def get(self, key): 127 def get(self, key):
125 samples_list = self._cache.GetFromFileListing(self._samples_path + '/') 128 samples_list = self._cache.GetFromFileListing(self._samples_path + '/')
126 return_list = [] 129 return_list = []
127 for dict_ in samples_list: 130 for dict_ in samples_list:
128 name = dict_['name'] 131 name = dict_['name']
129 description = dict_['description'] 132 description = dict_['description']
130 if name.startswith('__MSG_') or description.startswith('__MSG_'): 133 if name.startswith('__MSG_') or description.startswith('__MSG_'):
131 try: 134 try:
132 # Copy the sample dict so we don't change the dict in the cache. 135 # Copy the sample dict so we don't change the dict in the cache.
133 sample_data = dict_.copy() 136 sample_data = dict_.copy()
134 name_key = name[len('__MSG_'):-len('__')] 137 name_key = name[len('__MSG_'):-len('__')]
135 description_key = description[len('__MSG_'):-len('__')] 138 description_key = description[len('__MSG_'):-len('__')]
136 locale = sample_data['default_locale'] 139 locale = sample_data['default_locale']
137 for lang in self._GetAcceptedLanguages(): 140 for lang in self._GetAcceptedLanguages():
138 if lang in sample_data['locales']: 141 if lang in sample_data['locales']:
139 locale = lang 142 locale = lang
140 break 143 break
141 locale_data = sample_data['locales'][locale] 144 locale_data = sample_data['locales'][locale]
142 sample_data['name'] = locale_data[name_key]['message'] 145 sample_data['name'] = locale_data[name_key]['message']
143 sample_data['description'] = locale_data[description_key]['message'] 146 sample_data['description'] = locale_data[description_key]['message']
144 except Exception as e: 147 except Exception as e:
145 logging.error(e) 148 logging.error(e)
146 # Revert the sample to the original dict. 149 # Revert the sample to the original dict.
147 sample_data = dict_ 150 sample_data = dict_
148 return_list.append(sample_data) 151 return_list.append(sample_data)
149 else: 152 else:
150 return_list.append(dict_) 153 return_list.append(dict_)
151 return return_list 154 return return_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698