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 | 5 import logging |
| 6 import os | 6 import os |
| 7 | 7 |
| 8 class LocalFetcher(object): | 8 class LocalFetcher(object): |
| 9 """Class to fetch resources from local filesystem. | 9 """Class to fetch resources from local filesystem. |
| 10 """ | 10 """ |
| 11 def __init__(self, base_path): | 11 def __init__(self, base_path): |
| 12 self.base_path = base_path | 12 self._base_path = os.path.join(*base_path.split('/')) |
|
not at google - send to devlin
2012/06/07 04:43:57
Could you combine this and the stuff on line 24 in
cduvall
2012/06/08 00:39:23
Done.
| |
| 13 | 13 |
| 14 class _Resource(object): | 14 class _Resource(object): |
| 15 def __init__(self): | 15 def __init__(self): |
| 16 self.content = '' | 16 self.content = '' |
| 17 self.headers = {} | 17 self.headers = {} |
| 18 | 18 |
| 19 def _ReadFile(self, filename): | 19 def _ReadFile(self, filename): |
|
not at google - send to devlin
2012/06/07 04:43:57
Perhaps make this prepend base_path itself, rather
cduvall
2012/06/08 00:39:23
Done.
| |
| 20 with open(filename, 'r') as f: | 20 with open(filename, 'r') as f: |
| 21 return f.read() | 21 return f.read() |
| 22 | 22 |
| 23 def FetchResource(self, branch, path): | 23 def FetchResource(self, path): |
| 24 real_path = os.path.join(*path.split('/')) | 24 real_path = os.path.join(*path.split('/')) |
| 25 result = self._Resource() | 25 result = self._Resource() |
| 26 logging.info('Reading: ' + os.path.join(self.base_path, real_path)) | 26 logging.info('Reading: ' + os.path.join(self._base_path, real_path)) |
| 27 result.content = self._ReadFile(os.path.join(self.base_path, real_path)) | 27 result.content = self._ReadFile(os.path.join(self._base_path, real_path)) |
|
not at google - send to devlin
2012/06/07 04:43:57
Just pass content through to Resource in __init__
cduvall
2012/06/08 00:39:23
Done.
| |
| 28 return result | 28 return result |
| OLD | NEW |