OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 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 import logging |
| 6 |
5 from extensions_paths import JSON_TEMPLATES | 7 from extensions_paths import JSON_TEMPLATES |
6 from data_source import DataSource | 8 from data_source import DataSource |
7 | 9 |
8 | 10 |
9 class StringsDataSource(DataSource): | 11 class StringsDataSource(DataSource): |
10 '''Provides templates with access to a key to string mapping defined in a | 12 '''Provides templates with access to a key to string mapping defined in a |
11 JSON configuration file. | 13 JSON configuration file. |
12 ''' | 14 ''' |
13 def __init__(self, server_instance, _): | 15 def __init__(self, server_instance, _): |
14 self._cache = server_instance.compiled_fs_factory.ForJson( | 16 self._cache = server_instance.compiled_fs_factory.ForJson( |
15 server_instance.host_file_system_provider.GetTrunk()) | 17 server_instance.host_file_system_provider.GetTrunk()) |
16 | 18 |
17 def _GetStringsData(self): | 19 def _GetStringsData(self): |
18 return self._cache.GetFromFile('%s/strings.json' % JSON_TEMPLATES) | 20 return self._cache.GetFromFile('%s/strings.json' % JSON_TEMPLATES) |
19 | 21 |
20 def Cron(self): | 22 def Cron(self): |
21 return self._GetStringsData() | 23 return self._GetStringsData() |
22 | 24 |
23 def get(self, key): | 25 def get(self, key): |
24 return self._GetStringsData().Get().get(key) | 26 string = self._GetStringsData().Get().get(key) |
| 27 if string is None: |
| 28 logging.warning('String "%s" not found' % key) |
| 29 return string |
OLD | NEW |