Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 logging | |
| 6 import os | |
| 7 | |
| 5 SUBVERSION_URL = 'http://src.chromium.org/viewvc/chrome/' | 8 SUBVERSION_URL = 'http://src.chromium.org/viewvc/chrome/' |
| 6 TRUNK_URL = SUBVERSION_URL + 'trunk/' | 9 TRUNK_URL = SUBVERSION_URL + 'trunk/' |
| 7 BRANCH_URL = SUBVERSION_URL + 'branches/' | 10 BRANCH_URL = SUBVERSION_URL + 'branches/' |
| 8 | 11 |
| 9 class SubversionFetcher(object): | 12 class SubversionFetcher(object): |
| 10 """Class to fetch code from src.chromium.org. | 13 """Class to fetch docs from src.chromium.org. |
|
Aaron Boodman
2012/06/02 07:50:22
It will fetch lots of things. How about s/docs/res
cduvall
2012/06/02 19:12:05
Done.
| |
| 11 """ | 14 """ |
| 12 def __init__(self, urlfetch): | 15 def __init__(self, urlfetch): |
| 13 self.urlfetch = urlfetch | 16 self.urlfetch = urlfetch |
| 14 | 17 |
| 15 def _GetURLFromBranch(self, branch): | 18 def _GetURLFromBranch(self, branch): |
| 16 if branch == 'trunk': | 19 if branch == 'trunk': |
| 17 return TRUNK_URL | 20 return TRUNK_URL |
| 18 return BRANCH_URL + branch + '/' | 21 return BRANCH_URL + branch + '/' |
| 19 | 22 |
| 20 def FetchResource(self, branch, path): | 23 def FetchResource(self, branch, path): |
| 21 url = self._GetURLFromBranch(branch) + path | 24 url = self._GetURLFromBranch(branch) + path |
| 22 result = self.urlfetch.fetch(url) | 25 result = self.urlfetch.fetch(url) |
| 23 return result | 26 return result |
| 27 | |
| 28 class LocalFetcher(object): | |
|
Aaron Boodman
2012/06/02 07:50:22
Each class should typically be in a separate file
cduvall
2012/06/02 19:12:05
Done.
| |
| 29 """Class to fetch docs from local filesystem. | |
| 30 """ | |
| 31 class _Resource(object): | |
| 32 def __init__(self): | |
|
Aaron Boodman
2012/06/02 07:50:22
It seems like it would be more robust to pass in a
cduvall
2012/06/02 19:12:05
Done.
| |
| 33 self.content = '' | |
| 34 self.headers = {} | |
| 35 | |
| 36 def _ReadFile(self, filename): | |
| 37 with open(filename, 'r') as f: | |
| 38 return f.read() | |
| 39 | |
| 40 def FetchResource(self, branch, path): | |
| 41 result = self._Resource() | |
| 42 logging.info('Reading: ' + path) | |
| 43 result.content = self._ReadFile(path) | |
| 44 return result | |
| OLD | NEW |