summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/server2/strings_data_source.py
blob: 4e62680f05ea859851e285324cb0e1422e057958 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import logging

from extensions_paths import JSON_TEMPLATES
from data_source import DataSource


class StringsDataSource(DataSource):
  '''Provides templates with access to a key to string mapping defined in a
  JSON configuration file.
  '''
  def __init__(self, server_instance, _):
    self._cache = server_instance.compiled_fs_factory.ForJson(
        server_instance.host_file_system_provider.GetTrunk())

  def _GetStringsData(self):
    return self._cache.GetFromFile('%sstrings.json' % JSON_TEMPLATES)

  def Cron(self):
    return self._GetStringsData()

  def get(self, key):
    string = self._GetStringsData().Get().get(key)
    if string is None:
      logging.warning('String "%s" not found' % key)
    return string