| OLD | NEW |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 from google.appengine.api import files | 5 import cloudstorage |
| 6 import logging | 6 import logging |
| 7 import traceback | 7 import traceback |
| 8 | 8 |
| 9 import cache | 9 import cache |
| 10 | 10 |
| 11 def read(config_helper, file_name): | 11 def read(config_helper, file_name): |
| 12 content = cache.get_content(file_name) | 12 content = cache.get_content(file_name) |
| 13 if content: | 13 if content: |
| 14 return content | 14 return content |
| 15 # Sometimes remote calls fail for different reasons. Make sure we retry. | 15 # Sometimes remote calls fail for different reasons. Make sure we retry. |
| 16 full_path = config_helper.get_full_path(file_name) | 16 full_path = config_helper.get_full_path(file_name) |
| 17 for _ in [1, 2, 3]: | 17 try: |
| 18 try: | 18 with cloudstorage.open(full_path, 'r') as stream: |
| 19 with files.open(full_path, 'r') as stream: | 19 content = stream.read() |
| 20 content = stream.read() | 20 cache.set_content(file_name, content) |
| 21 cache.set_content(file_name, content) | 21 return content |
| 22 return content | 22 except: |
| 23 except: | 23 logging.error('Full path: %s' % full_path) |
| 24 logging.error('Full path: %s' % full_path) | 24 logging.error(traceback.format_exc()) |
| 25 logging.error(traceback.format_exc()) | |
| 26 return None | 25 return None |
| OLD | NEW |