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

Side by Side Diff: chrome/common/extensions/docs/server2/local_renderer.py

Issue 14856006: Docserver: achieve online vs offline (cron vs instance) behaviour at the object (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 7 months 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
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 os 5 import os
6 import urlparse 6 import urlparse
7 7
8 from empty_dir_file_system import EmptyDirFileSystem
9 from local_file_system import LocalFileSystem
8 from render_servlet import RenderServlet 10 from render_servlet import RenderServlet
9 from fake_fetchers import ConfigureFakeFetchers 11 from server_instance import ServerInstance
10 from servlet import Request 12 from servlet import Request
11 13
12 class LocalRenderer(object): 14 class LocalRenderer(object):
13 '''Renders pages fetched from the local file system. 15 '''Renders pages fetched from the local file system.
14 ''' 16 '''
15 def __init__(self, base_dir): 17 def __init__(self, base_dir):
16 self._base_dir = base_dir.replace(os.sep, '/').rstrip('/') 18 self._base_dir = base_dir.replace(os.sep, '/').rstrip('/')
17 19
18 def Render(self, path, headers=None, servlet=RenderServlet): 20 def Render(self, path, headers=None, offline=False, servlet=RenderServlet):
19 '''Renders |path|, returning a tuple of (status, contents, headers). 21 '''Renders |path|, returning a tuple of (status, contents, headers).
20 ''' 22 '''
21 headers = headers or {} 23 headers = headers or {}
22 # TODO(kalman): do this via a LocalFileSystem not this fake AppEngine stuff.
23 ConfigureFakeFetchers(os.path.join(self._base_dir, 'docs'))
24 url_path = urlparse.urlparse(path.replace(os.sep, '/')).path 24 url_path = urlparse.urlparse(path.replace(os.sep, '/')).path
25 return servlet(Request(url_path, headers)).Get() 25 if offline:
26 si = ServerInstance.CreateOffline(
27 'trunk',
28 host_file_system_type=LocalFileSystem,
29 app_samples_file_system=EmptyDirFileSystem())
30 else:
31 si = ServerInstance.CreateOnline(
32 'trunk',
33 host_file_system=LocalFileSystem(self._base_dir),
34 app_samples_file_system=EmptyDirFileSystem())
35 return servlet(Request(url_path, headers)).Get(server_instance=si)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698