| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import posixpath | 6 import posixpath |
| 7 | 7 |
| 8 from custom_logger import CustomLogger | 8 from custom_logger import CustomLogger |
| 9 from extensions_paths import EXAMPLES | 9 from extensions_paths import EXAMPLES |
| 10 from file_system_util import CreateURLsFromPaths | 10 from file_system_util import CreateURLsFromPaths |
| 11 from future import Future | 11 from future import All, Future |
| 12 from render_servlet import RenderServlet | 12 from render_servlet import RenderServlet |
| 13 from special_paths import SITE_VERIFICATION_FILE | 13 from special_paths import SITE_VERIFICATION_FILE |
| 14 from timer import Timer | 14 from timer import Timer |
| 15 | 15 |
| 16 | 16 |
| 17 _SUPPORTED_TARGETS = { | 17 _SUPPORTED_TARGETS = { |
| 18 'examples': (EXAMPLES, 'extensions/examples'), | 18 'examples': (EXAMPLES, 'extensions/examples'), |
| 19 } | 19 } |
| 20 | 20 |
| 21 | 21 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 return success_count == len(items) | 62 return success_count == len(items) |
| 63 | 63 |
| 64 | 64 |
| 65 class RenderRefresher(object): | 65 class RenderRefresher(object): |
| 66 '''Used to refresh any set of renderable resources. Currently only supports | 66 '''Used to refresh any set of renderable resources. Currently only supports |
| 67 assets related to extensions examples.''' | 67 assets related to extensions examples.''' |
| 68 def __init__(self, server_instance, request): | 68 def __init__(self, server_instance, request): |
| 69 self._server_instance = server_instance | 69 self._server_instance = server_instance |
| 70 self._request = request | 70 self._request = request |
| 71 | 71 |
| 72 def GetRefreshPaths(self): | 72 def Refresh(self): |
| 73 return _SUPPORTED_TARGETS.keys() | |
| 74 | |
| 75 def Refresh(self, path): | |
| 76 def render(path): | 73 def render(path): |
| 77 request = Request(path, self._request.host, self._request.headers) | 74 request = Request(path, self._request.host, self._request.headers) |
| 78 delegate = _SingletonRenderServletDelegate(self._server_instance) | 75 delegate = _SingletonRenderServletDelegate(self._server_instance) |
| 79 return RenderServlet(request, delegate).Get() | 76 return RenderServlet(request, delegate).Get() |
| 80 | 77 |
| 81 def request_files_in_dir(path, prefix='', strip_ext=None): | 78 def request_files_in_dir(path, prefix='', strip_ext=None): |
| 82 '''Requests every file found under |path| in this host file system, with | 79 '''Requests every file found under |path| in this host file system, with |
| 83 a request prefix of |prefix|. |strip_ext| is an optional list of file | 80 a request prefix of |prefix|. |strip_ext| is an optional list of file |
| 84 extensions that should be stripped from paths before requesting. | 81 extensions that should be stripped from paths before requesting. |
| 85 ''' | 82 ''' |
| 86 def maybe_strip_ext(name): | 83 def maybe_strip_ext(name): |
| 87 if name == SITE_VERIFICATION_FILE or not strip_ext: | 84 if name == SITE_VERIFICATION_FILE or not strip_ext: |
| 88 return name | 85 return name |
| 89 base, ext = posixpath.splitext(name) | 86 base, ext = posixpath.splitext(name) |
| 90 return base if ext in strip_ext else name | 87 return base if ext in strip_ext else name |
| 91 files = [maybe_strip_ext(name) | 88 files = [maybe_strip_ext(name) |
| 92 for name, _ in CreateURLsFromPaths(master_fs, path, prefix)] | 89 for name, _ in CreateURLsFromPaths(master_fs, path, prefix)] |
| 93 return _RequestEachItem(path, files, render) | 90 return _RequestEachItem(path, files, render) |
| 94 | 91 |
| 95 # Only support examples for now. | 92 return All(request_files_in_dir(dir, prefix=prefix) |
| 96 if path not in _SUPPORTED_TARGETS: | 93 for dir, prefix in _SUPPORTED_TARGETS.itervalues()) |
| 97 return Future(callback=lambda: False) | |
| 98 | 94 |
| 99 dir = _SUPPORTED_TARGETS[path][0] | |
| 100 prefix = _SUPPORTED_TARGETS[path][1] | |
| 101 return request_files_in_dir(dir, prefix=prefix) | |
| OLD | NEW |