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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/rietveld_file_system.py
===================================================================
--- chrome/common/extensions/docs/server2/rietveld_file_system.py (revision 0)
+++ chrome/common/extensions/docs/server2/rietveld_file_system.py (revision 0)
@@ -0,0 +1,67 @@
+# 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.
+
+import tarfile
+from StringIO import StringIO
+
+from file_system import FileSystem, FileNotFoundError, StatInfo, ToUnicode
+from future import Future
+from svn_constants import EXTENSIONS_PATH
+
+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.
+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.
+
+class _AsyncFetchFuture(object):
+ def __init__(self, paths, binary, tarball):
+ self._paths = paths
+ self._binary = binary
+ self._tarball = tarball
+
+ def Get(self):
+ tarball_result = self._tarball.Get()
+ if tarball_result.status_code != 200:
+ 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
+
+ try:
+ tar = tarfile.open(fileobj=StringIO(tarball_result.content))
+ except tarfile.TarError as e:
+ raise FileNotFoundError('Invalid tarball.')
+
+ value = {}
+ for path in self._paths:
+ try:
+ patched_file = tar.extractfile(RIETVELD_TARBALL_PATCHED_FILE % path)
+ except tarfile.TarError as e:
+ raise FileNotFoundError('File %s was deleted in the patchset.' % p)
+
+ value[path] = patched_file.read()
+ patched_file.close()
+ if not self._binary:
+ value[path] = ToUnicode(value[path])
+
+ 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
+
+class RietveldFileSystem(FileSystem):
+ """ Class to fetch resources from a patchset in Rietveld.
+ """
not at google - send to devlin 2013/04/26 23:53:53 Use ' not ".
方觉(Fang Jue) 2013/04/27 01:02:48 Done.
+ 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.
+ self._tarball = fetcher.FetchAsync(
+ RIETVELD_ISSUE_TARBALL % (issue, patchset))
+ self._patched_files = patched_files
+
+ def Read(self, paths, binary=False):
+ return Future(delegate=_AsyncFetchFuture(
+ paths,
+ binary,
+ self._tarball))
+
+ def Stat(self, path):
+ child_versions = {}
+ for f in self._patched_files:
+ if f.startswith(path):
+ child = f.split(path, 1)[1]
+ if '/' in child:
+ child = child.strip('/', 1)[0] + '/'
+ child_versions[child] = '0'
+ 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
Property changes on: chrome/common/extensions/docs/server2/rietveld_file_system.py
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698