Exemple #1
0
 def get(self, key):
     real_path = FormatKey(key)
     error = None
     for base_path in self._base_paths:
         try:
             return self._cache.GetFromFile(base_path + '/' + real_path)
         except FileNotFoundError as error:
             pass
     raise ValueError(str(error) + ': No intro found for "%s".' % key)
Exemple #2
0
 def Refresh(self):
     futures = []
     for root, _, files in self._file_system.Walk(self._dir):
         futures += [
             self._template_cache.GetFromFile(
                 posixpath.join(self._dir, root, FormatKey(f)))
             for f in files if posixpath.splitext(f)[1] == '.html'
         ]
     return All(futures)
 def get(self, key):
   path = FormatKey(key)
   def get_from_base_path(base_path):
     return self._cache.GetFromFile('%s/%s' % (base_path, path))
   for base_path in self._base_paths:
     try:
       return get_from_base_path(base_path)
     except FileNotFoundError:
       continue
   # Not found. Do the first operation again so that we get a stack trace - we
   # know that it'll fail.
   get_from_base_path(self._base_paths[0])
   raise AssertionError()
    def get(self, key):
        path = FormatKey(key)

        def get_from_base_path(base_path):
            return self._cache.GetFromFile(base_path + path).Get()

        base_paths = (INTROS_TEMPLATES, ARTICLES_TEMPLATES)
        for base_path in base_paths:
            try:
                return get_from_base_path(base_path)
            except FileNotFoundError:
                continue
        # Not found. Do the first operation again so that we get a stack trace - we
        # know that it'll fail.
        get_from_base_path(base_paths[0])
        raise AssertionError()
 def GetTemplate(self, base_path, template_name):
     try:
         return self._cache.GetFromFile('/'.join(
             (base_path, FormatKey(template_name))))
     except FileNotFoundError:
         return None