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

Side by Side Diff: chrome/common/extensions/docs/server2/rietveld_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, 8 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 import tarfile
6 from StringIO import StringIO
7
8 from file_system import FileSystem, FileNotFoundError, StatInfo, ToUnicode
9 from future import Future
10 from svn_constants import EXTENSIONS_PATH
11
12 RIETVELD_ISSUE_TARBALL = 'tarball/%s/%s'
not at google - send to devlin 2013/04/26 23:53:53 constants with hanging substitutions are odd... th
方觉(Fang Jue) 2013/04/27 01:02:48 Done.
13 RIETVELD_TARBALL_PATCHED_FILE = 'b/' + EXTENSIONS_PATH + '/%s'
not at google - send to devlin 2013/04/26 23:53:53 ditto. and string concatentation is slow, except p
方觉(Fang Jue) 2013/04/27 01:02:48 Done.
14
15 class _AsyncFetchFuture(object):
16 def __init__(self, paths, binary, tarball):
17 self._paths = paths
18 self._binary = binary
19 self._tarball = tarball
20
21 def Get(self):
22 tarball_result = self._tarball.Get()
23 if tarball_result.status_code != 200:
24 raise FileNotFoundError('Failed to download tarball.')
not at google - send to devlin 2013/04/26 23:53:53 this means we'll be unpacking the tarball every ti
方觉(Fang Jue) 2013/04/27 00:24:34 There's cache on RietveldFileSystem (memcache, see
not at google - send to devlin 2013/04/27 00:45:30 There is a cache, though it's still the case that
方觉(Fang Jue) 2013/04/29 12:46:23 Done. Now RietveldFileSystem has built-in cache. H
25
26 try:
27 tar = tarfile.open(fileobj=StringIO(tarball_result.content))
28 except tarfile.TarError as e:
29 raise FileNotFoundError('Invalid tarball.')
30
31 value = {}
32 for path in self._paths:
33 try:
34 patched_file = tar.extractfile(RIETVELD_TARBALL_PATCHED_FILE % path)
35 except tarfile.TarError as e:
36 raise FileNotFoundError('File %s was deleted in the patchset.' % p)
37
38 value[path] = patched_file.read()
39 patched_file.close()
40 if not self._binary:
41 value[path] = ToUnicode(value[path])
42
43 return value
not at google - send to devlin 2013/04/26 23:53:53 .. this is the value to cache. In fact, most of th
44
45 class RietveldFileSystem(FileSystem):
46 """ Class to fetch resources from a patchset in Rietveld.
47 """
not at google - send to devlin 2013/04/26 23:53:53 Use ' not ".
方觉(Fang Jue) 2013/04/27 01:02:48 Done.
48 def __init__(self, issue, patchset, patched_files, fetcher):
not at google - send to devlin 2013/04/26 23:53:53 pass through that PatchData object that you'll wri
方觉(Fang Jue) 2013/04/29 12:46:23 Done.
49 self._tarball = fetcher.FetchAsync(
50 RIETVELD_ISSUE_TARBALL % (issue, patchset))
51 self._patched_files = patched_files
52
53 def Read(self, paths, binary=False):
54 return Future(delegate=_AsyncFetchFuture(
55 paths,
56 binary,
57 self._tarball))
58
59 def Stat(self, path):
60 child_versions = {}
61 for f in self._patched_files:
62 if f.startswith(path):
63 child = f.split(path, 1)[1]
64 if '/' in child:
65 child = child.strip('/', 1)[0] + '/'
66 child_versions[child] = '0'
67 return StatInfo('0', child_versions)
not at google - send to devlin 2013/04/26 23:53:53 I can't actually really read this, besides, the St
方觉(Fang Jue) 2013/04/27 00:24:34 Different patchsets in an issue get different name
not at google - send to devlin 2013/04/27 00:45:30 Ok, that makes sense. Let's see how it turns out e
方觉(Fang Jue) 2013/04/27 01:02:48 But these are memcached (and are never intended to
not at google - send to devlin 2013/04/27 01:07:48 Yeah, exactly.
方觉(Fang Jue) 2013/04/29 12:46:23 Now, RietveldFileSystem is no longer wrapped by Ca
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698