| Index: chrome/common/extensions/docs/server2/subversion_file_system.py
|
| diff --git a/chrome/common/extensions/docs/server2/subversion_file_system.py b/chrome/common/extensions/docs/server2/subversion_file_system.py
|
| index 8257d19973c9b64b49c2f92cc24db519a1a19463..5c52fbc5538d43a56359cc66954106711af18f0a 100644
|
| --- a/chrome/common/extensions/docs/server2/subversion_file_system.py
|
| +++ b/chrome/common/extensions/docs/server2/subversion_file_system.py
|
| @@ -2,13 +2,53 @@
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| +import logging
|
| import re
|
| +import time
|
| import xml.dom.minidom as xml
|
| from xml.parsers.expat import ExpatError
|
|
|
| import file_system
|
| from future import Future
|
|
|
| +class _AsyncFetchFuture(object):
|
| + def __init__(self, paths, fetcher, binary):
|
| + # A list of tuples of the form (path, Future).
|
| + self._fetches = [(path, fetcher.FetchAsync(path)) for path in paths]
|
| + self._value = {}
|
| + self._error = None
|
| + self._binary = binary
|
| + self._start_time = time.time()
|
| +
|
| + def _ListDir(self, directory):
|
| + dom = xml.parseString(directory)
|
| + files = [elem.childNodes[0].data for elem in dom.getElementsByTagName('a')]
|
| + files.remove('..')
|
| + return files
|
| +
|
| + def Get(self):
|
| + try:
|
| + return self._DoGet()
|
| + finally:
|
| + logging.info("Fetching %s took %sms",
|
| + [fetch[0] for fetch in self._fetches],
|
| + (time.time() - self._start_time) * 1000)
|
| +
|
| + def _DoGet(self):
|
| + for path, future in self._fetches:
|
| + result = future.Get()
|
| + if result.status_code == 404:
|
| + raise file_system.FileNotFoundError(path)
|
| + elif path.endswith('/'):
|
| + self._value[path] = self._ListDir(result.content)
|
| + elif not self._binary:
|
| + self._value[path] = file_system._ProcessFileData(result.content, path)
|
| + else:
|
| + self._value[path] = result.content
|
| + if self._error is not None:
|
| + raise self._error
|
| + return self._value
|
| +
|
| class SubversionFileSystem(file_system.FileSystem):
|
| """Class to fetch resources from src.chromium.org.
|
| """
|
| @@ -58,9 +98,16 @@ class SubversionFileSystem(file_system.FileSystem):
|
| child_revisions[name] = rev.firstChild.nodeValue
|
| else:
|
| child_revisions[name + '/'] = rev.firstChild.nodeValue
|
| - return self.StatInfo(dir_revision, child_revisions)
|
| + return file_system.StatInfo(dir_revision, child_revisions)
|
|
|
| def Stat(self, path):
|
| + start_time = time.time()
|
| + try:
|
| + return self._DoStat(path)
|
| + finally:
|
| + logging.info("Stat %s took %sms", path, (time.time() - start_time) * 1000)
|
| +
|
| + def _DoStat(self, path):
|
| directory = path.rsplit('/', 1)[0]
|
| result = self._stat_fetcher.Fetch(directory + '/')
|
| if result.status_code == 404:
|
| @@ -72,35 +119,3 @@ class SubversionFileSystem(file_system.FileSystem):
|
| raise file_system.FileNotFoundError(path)
|
| stat_info.version = stat_info.child_versions[filename]
|
| return stat_info
|
| -
|
| -class _AsyncFetchFuture(object):
|
| - def __init__(self, paths, fetcher, binary):
|
| - # A list of tuples of the form (path, Future).
|
| - self._fetches = []
|
| - self._value = {}
|
| - self._error = None
|
| - self._fetches = [(path, fetcher.FetchAsync(path)) for path in paths]
|
| - self._binary = binary
|
| -
|
| - def _ListDir(self, directory):
|
| - dom = xml.parseString(directory)
|
| - files = [elem.childNodes[0].data for elem in dom.getElementsByTagName('a')]
|
| - if '..' in files:
|
| - files.remove('..')
|
| - return files
|
| -
|
| - def Get(self):
|
| - for path, future in self._fetches:
|
| - result = future.Get()
|
| - if result.status_code == 404:
|
| - raise file_system.FileNotFoundError(path)
|
| - elif path.endswith('/'):
|
| - self._value[path] = self._ListDir(result.content)
|
| - elif not self._binary:
|
| - self._value[path] = file_system._ProcessFileData(result.content, path)
|
| - else:
|
| - self._value[path] = result.content
|
| - if self._error is not None:
|
| - raise self._error
|
| - return self._value
|
| -
|
|
|