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

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: fixed zips 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 = map(lambda x: x.childNodes[0].data, dom.getElementsByTagName('a'))
not at google - send to devlin 2012/07/12 07:06:29 I think the "pythonic" way of doing map() is usual
cduvall 2012/07/12 18:09:02 Done.
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).content)
not at google - send to devlin 2012/07/12 07:06:29 need to pass recursive=True here? Or call _Recurs
cduvall 2012/07/12 18:09:02 Done.
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)
not at google - send to devlin 2012/07/12 07:06:29 I don't see how this works, doesn't this return HT
cduvall 2012/07/12 18:09:02 Done.
42 if recursive:
43 result.content = self._RecursiveList(self._ListDir(result.content), path)
44 return result
45
21 def FetchResource(self, path): 46 def FetchResource(self, path):
22 return self._url_fetcher.fetch(self._base_path + '/' + path) 47 return self._url_fetcher.fetch(self._base_path + '/' + path)
48
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698