| 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 27 matching lines...) Expand all Loading... |
| 66 def _GetConfig(self): | 70 def _GetConfig(self): |
| 67 return self._cache.GetFromFile(_CONFIG_PATH).Get() | 71 return self._cache.GetFromFile(_CONFIG_PATH).Get() |
| 68 | 72 |
| 69 def _CreateContentProvider(self, name, config): | 73 def _CreateContentProvider(self, name, config): |
| 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('%s: "chromium" must have a "dir" property' % name) |
| 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('%s: "github" must provide an "owner" and "repo"' % name) |
| 88 return None |
| 89 file_system = self._github_file_system_provider.Create( |
| 90 github_config['owner'], github_config['repo']) |
| 91 if 'dir' in github_config: |
| 92 file_system = ChrootFileSystem(file_system, github_config['dir']) |
| 80 else: | 93 else: |
| 81 logging.error('Content provider type "%s" not supported', type_) | 94 logging.error( |
| 95 '%s: content provider type "%s" not supported' % (name, type_)) |
| 82 return None | 96 return None |
| 83 | 97 |
| 84 return ContentProvider(name, | 98 return ContentProvider(name, |
| 85 self._compiled_fs_factory, | 99 self._compiled_fs_factory, |
| 86 file_system, | 100 file_system, |
| 87 supports_templates=supports_templates, | 101 supports_templates=supports_templates, |
| 88 supports_zip=supports_zip) | 102 supports_zip=supports_zip) |
| 89 | 103 |
| 90 def Cron(self): | 104 def Cron(self): |
| 91 for name, config in self._GetConfig().iteritems(): | 105 for name, config in self._GetConfig().iteritems(): |
| 92 self._CreateContentProvider(name, config).Cron() | 106 self._CreateContentProvider(name, config).Cron() |
| OLD | NEW |