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

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

Issue 10689144: Extensions Docs Server: Samples zip files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clean up and tests 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
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import xml.dom.minidom as xml
6
5 SUBVERSION_URL = 'http://src.chromium.org/chrome' 7 SUBVERSION_URL = 'http://src.chromium.org/chrome'
6 TRUNK_URL = SUBVERSION_URL + '/trunk' 8 TRUNK_URL = SUBVERSION_URL + '/trunk'
7 BRANCH_URL = SUBVERSION_URL + '/branches' 9 BRANCH_URL = SUBVERSION_URL + '/branches'
8 10
9 class SubversionFetcher(object): 11 class SubversionFetcher(object):
10 """Class to fetch resources from src.chromium.org. 12 """Class to fetch resources from src.chromium.org.
11 """ 13 """
12 def __init__(self, branch, base_path, url_fetcher): 14 def __init__(self, branch, base_path, url_fetcher):
13 self._base_path = self._GetURLFromBranch(branch) + '/' + base_path 15 self._base_path = self._GetURLFromBranch(branch) + '/' + base_path
14 self._url_fetcher = url_fetcher 16 self._url_fetcher = url_fetcher
15 17
16 def _GetURLFromBranch(self, branch): 18 def _GetURLFromBranch(self, branch):
17 if branch == 'trunk': 19 if branch == 'trunk':
18 return TRUNK_URL + '/src' 20 return TRUNK_URL + '/src'
19 return BRANCH_URL + '/' + branch + '/src' 21 return BRANCH_URL + '/' + branch + '/src'
20 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
21 def FetchResource(self, path): 47 def FetchResource(self, path):
22 return self._url_fetcher.fetch(self._base_path + '/' + path) 48 return self._url_fetcher.fetch(self._base_path + '/' + path)
49
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698