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

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

Issue 1151283007: Docserver overhaul: Gitiles away from me. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove inform_users template to fix presubmit failure (it's now a redirect) Created 5 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 logging 5 import logging
6 import os 6 import os
7 import traceback 7 import traceback
8 8
9 from chroot_file_system import ChrootFileSystem 9 from chroot_file_system import ChrootFileSystem
10 from content_provider import ContentProvider 10 from content_provider import ContentProvider
11 import environment 11 import environment
12 from extensions_paths import CONTENT_PROVIDERS, LOCAL_DEBUG_DIR 12 from extensions_paths import CONTENT_PROVIDERS, LOCAL_DEBUG_DIR
13 from future import Future 13 from future import All, Future
14 from gitiles_file_system import GitilesFileSystem
15 from local_file_system import LocalFileSystem 14 from local_file_system import LocalFileSystem
16 from third_party.json_schema_compiler.memoize import memoize 15 from third_party.json_schema_compiler.memoize import memoize
17 16
18 17
19 _IGNORE_MISSING_CONTENT_PROVIDERS = [False] 18 _IGNORE_MISSING_CONTENT_PROVIDERS = [False]
20 19
21 20
22 def IgnoreMissingContentProviders(fn): 21 def IgnoreMissingContentProviders(fn):
23 '''Decorates |fn| to ignore missing content providers during its run. 22 '''Decorates |fn| to ignore missing content providers during its run.
24 ''' 23 '''
(...skipping 12 matching lines...) Expand all
37 chrome/common/extensions/docs/templates/json/content_providers.json for its 36 chrome/common/extensions/docs/templates/json/content_providers.json for its
38 current state and a description of the format. 37 current state and a description of the format.
39 38
40 Returns ContentProvider instances based on how they're configured there. 39 Returns ContentProvider instances based on how they're configured there.
41 ''' 40 '''
42 41
43 def __init__(self, 42 def __init__(self,
44 object_store_creator, 43 object_store_creator,
45 compiled_fs_factory, 44 compiled_fs_factory,
46 host_file_system, 45 host_file_system,
47 github_file_system_provider,
48 gcs_file_system_provider): 46 gcs_file_system_provider):
49 self._object_store_creator = object_store_creator 47 self._object_store_creator = object_store_creator
50 self._compiled_fs_factory = compiled_fs_factory 48 self._compiled_fs_factory = compiled_fs_factory
51 self._host_file_system = host_file_system 49 self._host_file_system = host_file_system
52 self._github_file_system_provider = github_file_system_provider
53 self._gcs_file_system_provider = gcs_file_system_provider 50 self._gcs_file_system_provider = gcs_file_system_provider
54 self._cache = None 51 self._cache = None
55 52
56 # If running the devserver and there is a LOCAL_DEBUG_DIR, we 53 # If running the devserver and there is a LOCAL_DEBUG_DIR, we
57 # will read the content_provider configuration from there instead 54 # will read the content_provider configuration from there instead
58 # of fetching it from Gitiles or patch. 55 # of fetching it from Gitiles or patch.
59 if environment.IsDevServer() and os.path.exists(LOCAL_DEBUG_DIR): 56 if environment.IsDevServer() and os.path.exists(LOCAL_DEBUG_DIR):
60 local_fs = LocalFileSystem(LOCAL_DEBUG_DIR) 57 local_fs = LocalFileSystem(LOCAL_DEBUG_DIR)
61 conf_stat = None 58 conf_stat = None
62 try: 59 try:
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 return None 138 return None
142 bucket = gcs_config['bucket'] 139 bucket = gcs_config['bucket']
143 if not bucket.startswith('gs://'): 140 if not bucket.startswith('gs://'):
144 logging.error('%s: bucket %s should start with gs://' % (name, bucket)) 141 logging.error('%s: bucket %s should start with gs://' % (name, bucket))
145 return None 142 return None
146 bucket = bucket[len('gs://'):] 143 bucket = bucket[len('gs://'):]
147 file_system = self._gcs_file_system_provider.Create(bucket) 144 file_system = self._gcs_file_system_provider.Create(bucket)
148 if 'dir' in gcs_config: 145 if 'dir' in gcs_config:
149 file_system = ChrootFileSystem(file_system, gcs_config['dir']) 146 file_system = ChrootFileSystem(file_system, gcs_config['dir'])
150 147
151 elif 'github' in config:
152 github_config = config['github']
153 if 'owner' not in github_config or 'repo' not in github_config:
154 logging.error('%s: "github" must provide an "owner" and "repo"' % name)
155 return None
156 file_system = self._github_file_system_provider.Create(
157 github_config['owner'], github_config['repo'])
158 if 'dir' in github_config:
159 file_system = ChrootFileSystem(file_system, github_config['dir'])
160
161 else: 148 else:
162 logging.error('%s: content provider type not supported' % name) 149 logging.error('%s: content provider type not supported' % name)
163 return None 150 return None
164 151
165 return ContentProvider(name, 152 return ContentProvider(name,
166 self._compiled_fs_factory, 153 self._compiled_fs_factory,
167 file_system, 154 file_system,
168 self._object_store_creator, 155 self._object_store_creator,
169 default_extensions=default_extensions, 156 default_extensions=default_extensions,
170 supports_templates=supports_templates, 157 supports_templates=supports_templates,
171 supports_zip=supports_zip) 158 supports_zip=supports_zip)
172 159
173 def GetRefreshPaths(self): 160 def Refresh(self):
174 return self._GetConfig().keys()
175
176 def Refresh(self, path):
177 def safe(name, action, callback): 161 def safe(name, action, callback):
178 '''Safely runs |callback| for a ContentProvider called |name| by 162 '''Safely runs |callback| for a ContentProvider called |name| by
179 swallowing exceptions and turning them into a None return value. It's 163 swallowing exceptions and turning them into a None return value. It's
180 important to run all ContentProvider Refreshes even if some of them fail. 164 important to run all ContentProvider Refreshes even if some of them fail.
181 ''' 165 '''
182 try: 166 try:
183 return callback() 167 return callback()
184 except: 168 except:
185 if not _IGNORE_MISSING_CONTENT_PROVIDERS[0]: 169 if not _IGNORE_MISSING_CONTENT_PROVIDERS[0]:
186 logging.error('Error %s Refresh for ContentProvider "%s":\n%s' % 170 logging.error('Error %s Refresh for ContentProvider "%s":\n%s' %
187 (action, name, traceback.format_exc())) 171 (action, name, traceback.format_exc()))
188 return None 172 return None
189 173
190 config = self._GetConfig()[path] 174 def refresh_provider(path, config):
191 provider = self._CreateContentProvider(path, config) 175 provider = self._CreateContentProvider(path, config)
192 future = safe(path, 176 future = safe(path,
193 'initializing', 177 'initializing',
194 self._CreateContentProvider(path, config).Refresh) 178 self._CreateContentProvider(path, config).Refresh)
195 if future is None: 179 if future is None:
196 return Future(callback=lambda: True) 180 return Future(callback=lambda: True)
197 return Future(callback=lambda: safe(path, 'resolving', future.Get)) 181 return Future(callback=lambda: safe(path, 'resolving', future.Get))
182
183 return All(refresh_provider(path, config)
184 for path, config in self._GetConfig().iteritems())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698