Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/content_providers.py |
| diff --git a/chrome/common/extensions/docs/server2/content_providers.py b/chrome/common/extensions/docs/server2/content_providers.py |
| index 0c44d9e4a268428dcdc8fb4623bc7f947f229d93..9dedd94a71bb18ae53fb0badc7d6aaa1b7b4b778 100644 |
| --- a/chrome/common/extensions/docs/server2/content_providers.py |
| +++ b/chrome/common/extensions/docs/server2/content_providers.py |
| @@ -3,12 +3,15 @@ |
| # found in the LICENSE file. |
| import logging |
| +import os |
| import traceback |
| from chroot_file_system import ChrootFileSystem |
| from content_provider import ContentProvider |
| -from extensions_paths import CONTENT_PROVIDERS |
| +import environment |
| +from extensions_paths import CONTENT_PROVIDERS, LOCAL_DEBUG_DIR |
| from future import Gettable, Future |
| +from local_file_system import LocalFileSystem |
| from third_party.json_schema_compiler.memoize import memoize |
| @@ -23,11 +26,32 @@ class ContentProviders(object): |
| def __init__(self, |
| compiled_fs_factory, |
| host_file_system, |
| - github_file_system_provider): |
| + github_file_system_provider, |
| + gcs_file_system_provider): |
| self._compiled_fs_factory = compiled_fs_factory |
| self._host_file_system = host_file_system |
| self._github_file_system_provider = github_file_system_provider |
| - self._cache = compiled_fs_factory.ForJson(host_file_system) |
| + self._gcs_file_system_provider = gcs_file_system_provider |
| + self._cache = None |
| + |
| + # If running the devserver and there is a LOCAL_DEBUG_DIR, we |
| + # will read the content_provider configuration from there instead |
|
Jeffrey Yasskin
2014/01/29 01:08:08
Instead of what? Also, end comments with punctuati
Renato Mangini (chromium)
2014/01/31 02:29:04
Done.
|
| + if environment.IsDevServer() and os.path.exists(LOCAL_DEBUG_DIR): |
| + local_fs = LocalFileSystem(LOCAL_DEBUG_DIR) |
| + conf_stat = None |
| + try: |
| + conf_stat = local_fs.Stat(CONTENT_PROVIDERS) |
| + except: |
| + pass |
| + |
| + if conf_stat: |
| + logging.warn(("Using local debug folder (%s) for " |
| + "content_provider.json configuration") % LOCAL_DEBUG_DIR) |
| + self._using_debug_conf = True |
|
Jeffrey Yasskin
2014/01/29 01:08:08
This variable is never used. Do you need it?
Renato Mangini (chromium)
2014/01/31 02:29:04
Done.
|
| + self._cache = compiled_fs_factory.ForJson(local_fs) |
| + |
| + if not self._cache: |
| + self._cache = compiled_fs_factory.ForJson(host_file_system) |
| @memoize |
| def GetByName(self, name): |
| @@ -78,6 +102,20 @@ class ContentProviders(object): |
| return None |
| file_system = ChrootFileSystem(self._host_file_system, |
| chromium_config['dir']) |
| + elif 'gcs' in config: |
| + gcs_config = config['gcs'] |
| + if 'bucket' not in gcs_config: |
| + logging.error('%s: "gcs" must have a "bucket" property' % name) |
| + return None |
| + bucket = gcs_config['bucket'] |
| + if not bucket.startswith('gs://'): |
| + logging.error('%s: bucket %s should start with gs://' % (name, bucket)) |
| + return None |
| + bucket = bucket.lstrip('gs:/') |
|
Jeffrey Yasskin
2014/01/29 01:08:08
lstrip will drop a 'g' or 's' from the start of th
Renato Mangini (chromium)
2014/01/31 02:29:04
Done.
|
| + file_system = self._gcs_file_system_provider.Create(bucket) |
| + if 'dir' in gcs_config: |
| + file_system = ChrootFileSystem(file_system, gcs_config['dir']) |
| + |
| elif 'github' in config: |
| github_config = config['github'] |
| if 'owner' not in github_config or 'repo' not in github_config: |
| @@ -87,9 +125,9 @@ class ContentProviders(object): |
| github_config['owner'], github_config['repo']) |
| if 'dir' in github_config: |
| file_system = ChrootFileSystem(file_system, github_config['dir']) |
| + |
| else: |
| - logging.error( |
| - '%s: content provider type "%s" not supported' % (name, type_)) |
| + logging.error('%s: content provider type not supported' % name) |
| return None |
| return ContentProvider(name, |