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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 import logging
6 from operator import itemgetter
7 import posixpath
8
9 from chroot_file_system import ChrootFileSystem
10 from content_provider import ContentProvider
11 from svn_constants import JSON_PATH
12 from third_party.json_schema_compiler.memoize import memoize
13
14
15 _CONFIG_PATH = '%s/content_providers.json' % JSON_PATH
16
17
18 class ContentProviders(object):
19 '''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
20 ContentProvider instances based on how they're configured there.
21 '''
22
23 def __init__(self, compiled_fs_factory, host_file_system):
24 self._compiled_fs_factory = compiled_fs_factory
25 self._host_file_system = host_file_system
26 self._cache = compiled_fs_factory.ForJson(host_file_system)
27
28 @memoize
29 def GetByName(self, name):
30 config = self._GetConfig().get(name)
31 if config is None:
32 logging.error('No content provider found with name "%s"' % name)
33 return None
34 return self._CreateContentProvider(name, config)
35
36 @memoize
37 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.
38 serve_from_to_config = dict(
39 (config['serveFrom'], (name, config))
40 for name, config in self._GetConfig().iteritems())
41 path_parts = path.split('/')
42 for i in xrange(len(path_parts), -1, -1):
43 name_and_config = serve_from_to_config.get('/'.join(path_parts[:i]))
44 if name_and_config is not None:
45 return (self._CreateContentProvider(name_and_config[0],
46 name_and_config[1]),
47 '/'.join(path_parts[i:]))
48 return None, path
49
50 @memoize
51 def GetDefault(self):
52 for name, config in self._GetConfig().iteritems():
53 if config.get('default', False):
54 return self._CreateContentProvider(name, config)
55 logging.error('No default content provider')
56 return None
57
58 def _GetConfig(self):
59 return self._cache.GetFromFile(_CONFIG_PATH).Get()
60
61 def _CreateContentProvider(self, name, config):
62 type_ = config.get('type')
63 chroot = config.get('chroot', '')
64 supports_templates = config.get('supportsTemplates', False)
65 supports_zip = config.get('supportsZip', False)
66
67 if type_ == 'host':
68 file_system = self._host_file_system
69 else:
70 logging.error('Content provider type "%s" not supported', type_)
71 return None
72
73 return ContentProvider(name,
74 self._compiled_fs_factory,
75 ChrootFileSystem(file_system, chroot),
76 self._host_file_system,
77 supports_templates=supports_templates,
78 supports_zip=supports_zip)
79
80 def Cron(self):
81 for name, config in self._GetConfig().iteritems():
82 self._CreateContentProvider(name, config).Cron()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698