Chromium Code Reviews| 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 from operator import itemgetter | 6 from operator import itemgetter |
| 7 import posixpath | 7 import posixpath |
| 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 from svn_constants import JSON_PATH | 11 from svn_constants import JSON_PATH |
| 12 from third_party.json_schema_compiler.memoize import memoize | 12 from third_party.json_schema_compiler.memoize import memoize |
| 13 | 13 |
| 14 | 14 |
| 15 _CONFIG_PATH = '%s/content_providers.json' % JSON_PATH | 15 _CONFIG_PATH = '%s/content_providers.json' % JSON_PATH |
| 16 | 16 |
| 17 | 17 |
| 18 class ContentProviders(object): | 18 class ContentProviders(object): |
| 19 '''Implements the content_providers.json configuration; see | 19 '''Implements the content_providers.json configuration; see |
| 20 chrome/common/extensions/docs/templates/json/content_providers.json for its | 20 chrome/common/extensions/docs/templates/json/content_providers.json for its |
| 21 current state and a description of the format. | 21 current state and a description of the format. |
| 22 | 22 |
| 23 Returns ContentProvider instances based on how they're configured there. | 23 Returns ContentProvider instances based on how they're configured there. |
| 24 ''' | 24 ''' |
| 25 | 25 |
| 26 def __init__(self, compiled_fs_factory, host_file_system): | 26 def __init__(self, |
| 27 compiled_fs_factory, | |
| 28 host_file_system, | |
| 29 github_file_system_provider): | |
| 27 self._compiled_fs_factory = compiled_fs_factory | 30 self._compiled_fs_factory = compiled_fs_factory |
| 28 self._host_file_system = host_file_system | 31 self._host_file_system = host_file_system |
| 32 self._github_file_system_provider = github_file_system_provider | |
| 29 self._cache = compiled_fs_factory.ForJson(host_file_system) | 33 self._cache = compiled_fs_factory.ForJson(host_file_system) |
| 30 | 34 |
| 31 @memoize | 35 @memoize |
| 32 def GetByName(self, name): | 36 def GetByName(self, name): |
| 33 '''Gets the ContentProvider keyed by |name| in content_providers.json, or | 37 '''Gets the ContentProvider keyed by |name| in content_providers.json, or |
| 34 None of there is no such content provider. | 38 None of there is no such content provider. |
| 35 ''' | 39 ''' |
| 36 config = self._GetConfig().get(name) | 40 config = self._GetConfig().get(name) |
| 37 if config is None: | 41 if config is None: |
| 38 logging.error('No content provider found with name "%s"' % name) | 42 logging.error('No content provider found with name "%s"' % name) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 supports_templates = config.get('supportsTemplates', False) | 74 supports_templates = config.get('supportsTemplates', False) |
| 71 supports_zip = config.get('supportsZip', False) | 75 supports_zip = config.get('supportsZip', False) |
| 72 | 76 |
| 73 if 'chromium' in config: | 77 if 'chromium' in config: |
| 74 chromium_config = config['chromium'] | 78 chromium_config = config['chromium'] |
| 75 if 'dir' not in chromium_config: | 79 if 'dir' not in chromium_config: |
| 76 logging.error('"chromium" must have a "dir" property') | 80 logging.error('"chromium" must have a "dir" property') |
| 77 return None | 81 return None |
| 78 file_system = ChrootFileSystem(self._host_file_system, | 82 file_system = ChrootFileSystem(self._host_file_system, |
| 79 chromium_config['dir']) | 83 chromium_config['dir']) |
| 84 elif 'github' in config: | |
| 85 github_config = config['github'] | |
| 86 if 'owner' not in github_config or 'repo' not in github_config: | |
| 87 logging.error('"github" must provide a owner and repo') | |
|
Jeffrey Yasskin
2013/11/06 04:00:19
I think your error should include the name of the
not at google - send to devlin
2013/11/06 23:00:13
Good idea.
| |
| 88 return None | |
| 89 file_system = self._github_file_system_provider.Create( | |
|
Jeffrey Yasskin
2013/11/06 04:00:19
Does github need to provide a chroot too?
not at google - send to devlin
2013/11/06 23:00:13
Not yet, but might as well.
| |
| 90 github_config['owner'], github_config['repo']) | |
| 80 else: | 91 else: |
| 81 logging.error('Content provider type "%s" not supported', type_) | 92 logging.error('Content provider type "%s" not supported', type_) |
| 82 return None | 93 return None |
| 83 | 94 |
| 84 return ContentProvider(name, | 95 return ContentProvider(name, |
| 85 self._compiled_fs_factory, | 96 self._compiled_fs_factory, |
| 86 file_system, | 97 file_system, |
| 87 supports_templates=supports_templates, | 98 supports_templates=supports_templates, |
| 88 supports_zip=supports_zip) | 99 supports_zip=supports_zip) |
| 89 | 100 |
| 90 def Cron(self): | 101 def Cron(self): |
| 91 for name, config in self._GetConfig().iteritems(): | 102 for name, config in self._GetConfig().iteritems(): |
| 92 self._CreateContentProvider(name, config).Cron() | 103 self._CreateContentProvider(name, config).Cron() |
| OLD | NEW |