| OLD | NEW |
| (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 xml.dom.minidom as xml | |
| 6 | |
| 7 SUBVERSION_URL = 'http://src.chromium.org/chrome' | |
| 8 TRUNK_URL = SUBVERSION_URL + '/trunk' | |
| 9 BRANCH_URL = SUBVERSION_URL + '/branches' | |
| 10 | |
| 11 class SubversionFetcher(object): | |
| 12 """Class to fetch resources from src.chromium.org. | |
| 13 """ | |
| 14 def __init__(self, branch, base_path, url_fetcher): | |
| 15 self._base_path = self._GetURLFromBranch(branch) + '/' + base_path | |
| 16 self._url_fetcher = url_fetcher | |
| 17 | |
| 18 def _GetURLFromBranch(self, branch): | |
| 19 if branch == 'trunk': | |
| 20 return TRUNK_URL + '/src' | |
| 21 return BRANCH_URL + '/' + branch + '/src' | |
| 22 | |
| 23 def _ListDir(self, directory): | |
| 24 dom = xml.parseString(directory) | |
| 25 files = [elem.childNodes[0].data for elem in dom.getElementsByTagName('a')] | |
| 26 if '..' in files: | |
| 27 files.remove('..') | |
| 28 return files | |
| 29 | |
| 30 def _RecursiveList(self, files, base): | |
| 31 all_files = [] | |
| 32 for filename in files: | |
| 33 if filename.endswith('/'): | |
| 34 dir_name = base + '/' + filename.split('/')[-2] | |
| 35 all_files.extend(self.ListDirectory(dir_name, True).content) | |
| 36 else: | |
| 37 all_files.append(base + '/' + filename) | |
| 38 return all_files | |
| 39 | |
| 40 def ListDirectory(self, path, recursive=False): | |
| 41 result = self._url_fetcher.fetch(self._base_path + '/' + path) | |
| 42 result.content = self._ListDir(result.content) | |
| 43 if recursive: | |
| 44 result.content = self._RecursiveList(result.content, path) | |
| 45 return result | |
| 46 | |
| 47 def FetchResource(self, path): | |
| 48 return self._url_fetcher.fetch(self._base_path + '/' + path) | |
| 49 | |
| OLD | NEW |