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

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

Issue 14125010: Docserver: Add support for viewing docs with a codereview patch applied (Closed) Base URL: https://src.chromium.org/svn/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
Property Changes:
Added: svn:eol-style
+ LF
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 from file_system import FileSystem, StatInfo, FileNotFoundError
6 from future import Future
7 import logging
8
9 class _AsyncFetchFuture(object):
10 def __init__(self, paths, binary, svn_future, patched_future):
11 self._svn_future = svn_future
12 self._patched_future = patched_future
13
14 def Get(self):
15 value = self._svn_future.Get()
16 value.update(self._patched_future.Get())
17 return value
18
19 class PatchedFileSystem(FileSystem):
20 """ Class to fetch resources with a patch applied.
21 """
22 def __init__(self, patched_files, svn_file_system, patch_file_system):
23 self._patched_files = patched_files
24 self._svn_file_system = svn_file_system
25 self._patch_file_system = patch_file_system
26
27 def Read(self, paths, binary=False):
28 # TODO(fj): What about directory listing?
方觉(Fang Jue) 2013/04/29 12:46:23 I found that directory listing is used in APIListD
not at google - send to devlin 2013/04/29 16:38:49 Do you mean normally? As in the server right now,
方觉(Fang Jue) 2013/04/30 01:07:11 It's specific to the patched file system. When fet
29 patched_paths = list(set(paths) & set(self._patched_files))
30 unpatched_paths = list(set(paths) - set(self._patched_files))
31 return Future(delegate=_AsyncFetchFuture(
32 paths,
33 binary,
34 self._svn_file_system.Read(unpatched_paths, binary),
35 self._patch_file_system.Read(patched_paths, binary)))
36
37 def _FindChildren(self, path):
38 children = []
39 for p in self._patched_files:
40 if p.startswith(path):
41 child = p.split(path, 1)[1]
42 if '/' in child:
43 child = child.split('/', 1)[0] + '/'
44 children.append(child)
45 return children
46
47 # Create dummy stat info for added files in a patch.
48 def _TryCreateStatInfo(self, path):
49 if path.endswith('/'):
50 children = self._FindChildren(path)
51 if len(children) == 0:
52 return None
53 return StatInfo('0', {child: '0' for child in children})
54 elif path in self._patched_files:
55 return StatInfo('0', {})
56 else:
57 return None
58
59 # We assume that a patchset, once created, will never change. For any new
60 # files, returned version will be '0'. Different patchesets will have
61 # separate caches so they won't interfere with each other even if versions
62 # are all '0'.
not at google - send to devlin 2013/04/29 16:38:49 I was thinking about this more and we shouldn't be
方觉(Fang Jue) 2013/04/30 14:25:08 Done.
63 def Stat(self, path):
64 try:
65 stat_info = self._svn_file_system.Stat(path)
66 if stat_info.child_versions:
67 # New files can be added to the directory in the patch
68 added_children = (set(self._FindChildren(path)) -
69 set(stat_info.child_versions.keys()))
70 stat_info.child_versions.update(
71 {child: '0' for child in added_children})
72 except FileNotFoundError as e:
73 # Try to create a dummy stat if a new file/directory is added.
74 stat_info = self._TryCreateStatInfo(path)
75 if stat_info is None:
76 raise e
77 return stat_info
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698