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 logging |
| 6 import os |
| 7 |
| 8 class LocalFetcher(object): |
| 9 """Class to fetch resources from local filesystem. |
| 10 """ |
| 11 def __init__(self, base_path): |
| 12 self.base_path = base_path |
| 13 |
| 14 class _Resource(object): |
| 15 def __init__(self): |
| 16 self.content = '' |
| 17 self.headers = {} |
| 18 |
| 19 def _ReadFile(self, filename): |
| 20 with open(filename, 'r') as f: |
| 21 return f.read() |
| 22 |
| 23 def FetchResource(self, branch, path): |
| 24 real_path = os.path.join(*path.split('/')) |
| 25 result = self._Resource() |
| 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)) |
| 28 return result |
OLD | NEW |