OLD | NEW |
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 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 gcs_file_system_provider): | 48 gcs_file_system_provider): |
49 self._object_store_creator = object_store_creator | 49 self._object_store_creator = object_store_creator |
50 self._compiled_fs_factory = compiled_fs_factory | 50 self._compiled_fs_factory = compiled_fs_factory |
51 self._host_file_system = host_file_system | 51 self._host_file_system = host_file_system |
52 self._github_file_system_provider = github_file_system_provider | 52 self._github_file_system_provider = github_file_system_provider |
53 self._gcs_file_system_provider = gcs_file_system_provider | 53 self._gcs_file_system_provider = gcs_file_system_provider |
54 self._cache = None | 54 self._cache = None |
55 | 55 |
56 # If running the devserver and there is a LOCAL_DEBUG_DIR, we | 56 # If running the devserver and there is a LOCAL_DEBUG_DIR, we |
57 # will read the content_provider configuration from there instead | 57 # will read the content_provider configuration from there instead |
58 # of fetching it from SVN trunk or patch. | 58 # of fetching it from Gitiles or patch. |
59 if environment.IsDevServer() and os.path.exists(LOCAL_DEBUG_DIR): | 59 if environment.IsDevServer() and os.path.exists(LOCAL_DEBUG_DIR): |
60 local_fs = LocalFileSystem(LOCAL_DEBUG_DIR) | 60 local_fs = LocalFileSystem(LOCAL_DEBUG_DIR) |
61 conf_stat = None | 61 conf_stat = None |
62 try: | 62 try: |
63 conf_stat = local_fs.Stat(CONTENT_PROVIDERS) | 63 conf_stat = local_fs.Stat(CONTENT_PROVIDERS) |
64 except: | 64 except: |
65 pass | 65 pass |
66 | 66 |
67 if conf_stat: | 67 if conf_stat: |
68 logging.warn(("Using local debug folder (%s) for " | 68 logging.warn(("Using local debug folder (%s) for " |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 return None | 163 return None |
164 | 164 |
165 return ContentProvider(name, | 165 return ContentProvider(name, |
166 self._compiled_fs_factory, | 166 self._compiled_fs_factory, |
167 file_system, | 167 file_system, |
168 self._object_store_creator, | 168 self._object_store_creator, |
169 default_extensions=default_extensions, | 169 default_extensions=default_extensions, |
170 supports_templates=supports_templates, | 170 supports_templates=supports_templates, |
171 supports_zip=supports_zip) | 171 supports_zip=supports_zip) |
172 | 172 |
173 def Cron(self): | 173 def GetRefreshPaths(self): |
| 174 return self._GetConfig().keys() |
| 175 |
| 176 def Refresh(self, path): |
174 def safe(name, action, callback): | 177 def safe(name, action, callback): |
175 '''Safely runs |callback| for a ContentProvider called |name| by | 178 '''Safely runs |callback| for a ContentProvider called |name| by |
176 swallowing exceptions and turning them into a None return value. It's | 179 swallowing exceptions and turning them into a None return value. It's |
177 important to run all ContentProvider Crons even if some of them fail. | 180 important to run all ContentProvider Refreshes even if some of them fail. |
178 ''' | 181 ''' |
179 try: | 182 try: |
180 return callback() | 183 return callback() |
181 except: | 184 except: |
182 if not _IGNORE_MISSING_CONTENT_PROVIDERS[0]: | 185 if not _IGNORE_MISSING_CONTENT_PROVIDERS[0]: |
183 logging.error('Error %s Cron for ContentProvider "%s":\n%s' % | 186 logging.error('Error %s Refresh for ContentProvider "%s":\n%s' % |
184 (action, name, traceback.format_exc())) | 187 (action, name, traceback.format_exc())) |
185 return None | 188 return None |
186 | 189 |
187 futures = [(name, safe(name, | 190 config = self._GetConfig()[path] |
188 'initializing', | 191 provider = self._CreateContentProvider(path, config) |
189 self._CreateContentProvider(name, config).Cron)) | 192 future = safe(path, |
190 for name, config in self._GetConfig().iteritems()] | 193 'initializing', |
191 return Future(callback= | 194 self._CreateContentProvider(path, config).Refresh) |
192 lambda: [safe(name, 'resolving', f.Get) for name, f in futures if f]) | 195 if future is None: |
| 196 return Future(callback=lambda: True) |
| 197 return Future(callback=lambda: safe(path, 'resolving', future.Get)) |
OLD | NEW |