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

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

Issue 55913003: Docserver: Fix 3 issues relating to finding API references in sample files, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
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 posixpath 8 import posixpath
9 import re 9 import re
10 import traceback 10 import traceback
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 def Create(self, request): 49 def Create(self, request):
50 '''Returns a new SamplesDataSource bound to |request|. 50 '''Returns a new SamplesDataSource bound to |request|.
51 ''' 51 '''
52 return SamplesDataSource(self._extensions_cache, 52 return SamplesDataSource(self._extensions_cache,
53 self._apps_cache, 53 self._apps_cache,
54 self._extension_samples_path, 54 self._extension_samples_path,
55 self._base_path, 55 self._base_path,
56 request) 56 request)
57 57
58 def _GetAPIItems(self, js_file): 58 def _GetAPIItems(self, js_file):
59 chrome_regex = '(chrome\.[a-zA-Z0-9\.]+)' 59 chrome_regex = r'(chrome\.[a-zA-Z0-9\.]+)'
60 calls = set(re.findall(chrome_regex, js_file)) 60 calls = set(re.findall(chrome_regex, js_file))
61 # Find APIs that have been assigned into variables. 61 # Find APIs that have been assigned into variables.
62 assigned_vars = dict(re.findall('var\s*([^\s]+)\s*=\s*%s;' % chrome_regex, 62 assigned_vars = dict(
63 js_file)) 63 re.findall(r'var\s*([^\s]+)\s*=\s*%s;' % chrome_regex, js_file))
64 # Replace the variable name with the full API name. 64 # Replace the variable name with the full API name.
65 for var_name, value in assigned_vars.iteritems(): 65 for var_name, value in assigned_vars.iteritems():
Jeffrey Yasskin 2013/11/01 18:00:24 You might be able to make this loop more efficient
66 js_file = js_file.replace(var_name, value) 66 js_file = re.compile(r'\b%s\b' % var_name).sub(value, js_file)
not at google - send to devlin 2013/11/01 17:12:04 this is the most important change.
Jeffrey Yasskin 2013/11/01 18:00:24 Instead of re.compile(variable_string).sub(...), u
Jeffrey Yasskin 2013/11/01 18:00:24 You probably want re.escape(var_name) in case it c
67 return calls.union(re.findall(chrome_regex, js_file)) 67 return calls.union(re.findall(chrome_regex, js_file))
Jeffrey Yasskin 2013/11/01 18:00:24 Wait a second, you're just trying to find the APIs
not at google - send to devlin 2013/11/04 21:51:01 I got a little bit lost in your comments there + t
68 68
69 def _GetDataFromManifest(self, path, file_system): 69 def _GetDataFromManifest(self, path, file_system):
70 manifest = file_system.ReadSingle(path + '/manifest.json').Get() 70 manifest = file_system.ReadSingle(path + '/manifest.json').Get()
71 try: 71 try:
72 manifest_json = json.loads(json_comment_eater.Nom(manifest)) 72 manifest_json = json.loads(json_comment_eater.Nom(manifest))
73 except ValueError as e: 73 except ValueError as e:
74 logging.error('Error parsing manifest.json for %s: %s' % (path, e)) 74 logging.error('Error parsing manifest.json for %s: %s' % (path, e))
75 return None 75 return None
76 l10n_data = { 76 l10n_data = {
77 'name': manifest_json.get('name', ''), 77 'name': manifest_json.get('name', ''),
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 else: 230 else:
231 dict_['id'] = self._GetSampleId(name) 231 dict_['id'] = self._GetSampleId(name)
232 return_list.append(dict_) 232 return_list.append(dict_)
233 return return_list 233 return return_list
234 234
235 def get(self, key): 235 def get(self, key):
236 return { 236 return {
237 'apps': lambda: self._CreateSamplesDict('apps'), 237 'apps': lambda: self._CreateSamplesDict('apps'),
238 'extensions': lambda: self._CreateSamplesDict('extensions') 238 'extensions': lambda: self._CreateSamplesDict('extensions')
239 }.get(key, lambda: {})() 239 }.get(key, lambda: {})()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698