Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/patched_file_system.py |
| =================================================================== |
| --- chrome/common/extensions/docs/server2/patched_file_system.py (revision 0) |
| +++ chrome/common/extensions/docs/server2/patched_file_system.py (revision 0) |
| @@ -0,0 +1,47 @@ |
| +# 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. |
| + |
| +from file_system import FileSystem |
| +from future import Future |
| +import logging |
| + |
| +class _AsyncFetchFuture(object): |
| + def __init__(self, paths, binary, patched_files, svn_file_system, |
| + patch_file_system): |
| + patched_paths = [] |
| + unpatched_paths = [] |
| + for path in paths: |
| + if path in patched_files: |
| + patched_paths.append(path) |
| + else: |
| + unpatched_paths.append(path) |
|
not at google - send to devlin
2013/04/26 23:53:53
you may want to use set()s everywhere for these pa
方觉(Fang Jue)
2013/04/27 01:02:48
Done. Python is awesome!
|
| + logging.info(patched_paths) |
| + logging.info(unpatched_paths) |
| + self._svn_future = svn_file_system.Read(unpatched_paths, binary) |
| + self._patched_future = patch_file_system.Read(patched_paths, binary) |
|
not at google - send to devlin
2013/04/26 23:53:53
Just pass these futures directly in through the co
方觉(Fang Jue)
2013/04/27 01:02:48
Done.
|
| + |
| + def Get(self): |
| + value = self._svn_future.Get() |
| + value.update(self._patched_future.Get()) |
| + return value |
| + |
| +class PatchedFileSystem(FileSystem): |
| + """ Class to fetch resources with a patch applied. |
| + """ |
| + def __init__(self, patched_files, svn_file_system, patch_file_system): |
| + self._patched_files = patched_files |
| + self._svn_file_system = svn_file_system |
| + self._patch_file_system = patch_file_system |
| + |
| + def Read(self, paths, binary=False): |
| + return Future(delegate=_AsyncFetchFuture( |
| + paths, |
| + binary, |
| + self._patched_files, |
| + self._svn_file_system, |
| + self._patch_file_system)) |
| + |
| + # We assume that a patchset, once created, will never change. |
| + def Stat(self, path): |
| + return self._svn_file_system.Stat(path) |
| Property changes on: chrome/common/extensions/docs/server2/patched_file_system.py |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |