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

Unified Diff: chrome/common/extensions/docs/server2/content_providers.py

Issue 54603010: Docserver: Implement the content providers infrastructure, where a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..51e7814797ede01f37390dcf4106e3a381a19501
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/content_providers.py
@@ -0,0 +1,82 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import logging
+from operator import itemgetter
+import posixpath
+
+from chroot_file_system import ChrootFileSystem
+from content_provider import ContentProvider
+from svn_constants import JSON_PATH
+from third_party.json_schema_compiler.memoize import memoize
+
+
+_CONFIG_PATH = '%s/content_providers.json' % JSON_PATH
+
+
+class ContentProviders(object):
+ '''Implements the content_providers.json configuration. Returns
Jeffrey Yasskin 2013/11/04 21:21:18 Document or link to documentation of the format of
not at google - send to devlin 2013/11/04 23:34:49 Done. Documentation added to content_providers.jso
+ ContentProvider instances based on how they're configured there.
+ '''
+
+ def __init__(self, compiled_fs_factory, host_file_system):
+ self._compiled_fs_factory = compiled_fs_factory
+ self._host_file_system = host_file_system
+ self._cache = compiled_fs_factory.ForJson(host_file_system)
+
+ @memoize
+ def GetByName(self, name):
+ config = self._GetConfig().get(name)
+ if config is None:
+ logging.error('No content provider found with name "%s"' % name)
+ return None
+ return self._CreateContentProvider(name, config)
+
+ @memoize
+ def GetByServlet(self, path):
Jeffrey Yasskin 2013/11/04 21:21:18 Docstring what this function means, as opposed to
not at google - send to devlin 2013/11/04 23:34:49 Done.
+ serve_from_to_config = dict(
+ (config['serveFrom'], (name, config))
+ for name, config in self._GetConfig().iteritems())
+ path_parts = path.split('/')
+ for i in xrange(len(path_parts), -1, -1):
+ name_and_config = serve_from_to_config.get('/'.join(path_parts[:i]))
+ if name_and_config is not None:
+ return (self._CreateContentProvider(name_and_config[0],
+ name_and_config[1]),
+ '/'.join(path_parts[i:]))
+ return None, path
+
+ @memoize
+ def GetDefault(self):
+ for name, config in self._GetConfig().iteritems():
+ if config.get('default', False):
+ return self._CreateContentProvider(name, config)
+ logging.error('No default content provider')
+ return None
+
+ def _GetConfig(self):
+ return self._cache.GetFromFile(_CONFIG_PATH).Get()
+
+ def _CreateContentProvider(self, name, config):
+ type_ = config.get('type')
+ chroot = config.get('chroot', '')
+ supports_templates = config.get('supportsTemplates', False)
+ supports_zip = config.get('supportsZip', False)
+
+ if type_ == 'host':
+ file_system = self._host_file_system
+ else:
+ logging.error('Content provider type "%s" not supported', type_)
+ return None
+
+ return ContentProvider(name,
+ self._compiled_fs_factory,
+ ChrootFileSystem(file_system, chroot),
+ self._host_file_system,
+ supports_templates=supports_templates,
+ supports_zip=supports_zip)
+
+ def Cron(self):
+ for name, config in self._GetConfig().iteritems():
+ self._CreateContentProvider(name, config).Cron()

Powered by Google App Engine
This is Rietveld 408576698