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

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

Issue 10704252: Extensions Docs Server: Internal file system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed up Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2012 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 re
6 import xml.dom.minidom as xml
7
8 from file_system import FileSystem
9 from future import Future
10
11 class SubversionFileSystem(FileSystem):
12 """Class to fetch resources from src.chromium.org.
13 """
14 def __init__(self, fetcher):
15 self._fetcher = fetcher
16
17 def Read(self, paths):
18 return Future(delegate=_AsyncFetchFuture(paths, self._fetcher))
19
20 def Stat(self, path):
21 directory = path.rsplit('/', 1)[0]
22 dir_html = self._fetcher.Fetch(directory + '/').content
23 return self.StatInfo(int(re.search('([0-9]+)', dir_html).group(0)))
24
25 class _AsyncFetchFuture(object):
26 def __init__(self, paths, fetcher):
27 # A list of tuples of the form (path, Future).
28 self._fetches = []
29 self._value = {}
30 self._error = None
31 self._fetches = [(path, fetcher.FetchAsync(path)) for path in paths]
32
33 def _ListDir(self, directory):
34 dom = xml.parseString(directory)
35 files = [elem.childNodes[0].data for elem in dom.getElementsByTagName('a')]
36 if '..' in files:
37 files.remove('..')
38 return files
39
40 def Get(self):
41 for path, future in self._fetches:
42 result = future.Get()
43 if result.status_code == 404:
44 self._value[path] = None
45 elif path.endswith('/'):
46 self._value[path] = self._ListDir(result.content)
47 else:
48 self._value[path] = result.content
49 if self._error is not None:
50 raise self._error
51 return self._value
52
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698