OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 | 5 import logging |
6 import posixpath | 6 import posixpath |
7 import traceback | 7 import traceback |
8 | 8 |
9 from data_source import DataSource | 9 from data_source import DataSource |
10 from docs_server_utils import FormatKey | 10 from docs_server_utils import FormatKey |
(...skipping 16 matching lines...) Expand all Loading... |
27 self._file_system = server_instance.host_file_system_provider.GetMaster() | 27 self._file_system = server_instance.host_file_system_provider.GetMaster() |
28 | 28 |
29 def get(self, path): | 29 def get(self, path): |
30 try: | 30 try: |
31 return self._template_cache.GetFromFile('%s%s' % | 31 return self._template_cache.GetFromFile('%s%s' % |
32 (self._dir, FormatKey(path))).Get() | 32 (self._dir, FormatKey(path))).Get() |
33 except FileNotFoundError: | 33 except FileNotFoundError: |
34 logging.warning(traceback.format_exc()) | 34 logging.warning(traceback.format_exc()) |
35 return None | 35 return None |
36 | 36 |
37 def Refresh(self, path): | 37 def Refresh(self): |
38 futures = [] | 38 futures = [] |
39 for root, _, files in self._file_system.Walk(self._dir): | 39 for root, _, files in self._file_system.Walk(self._dir): |
40 futures += [self._template_cache.GetFromFile( | 40 futures += [self._template_cache.GetFromFile( |
41 posixpath.join(self._dir, root, FormatKey(f))) | 41 posixpath.join(self._dir, root, FormatKey(f))) |
42 for f in files | 42 for f in files |
43 if posixpath.splitext(f)[1] == '.html'] | 43 if posixpath.splitext(f)[1] == '.html'] |
44 return All(futures) | 44 return All(futures) |
45 | 45 |
46 | 46 |
47 class ArticleDataSource(TemplateDataSource): | 47 class ArticleDataSource(TemplateDataSource): |
48 '''Serves templates for Articles. | 48 '''Serves templates for Articles. |
49 ''' | 49 ''' |
50 _BASE = ARTICLES_TEMPLATES | 50 _BASE = ARTICLES_TEMPLATES |
51 | 51 |
52 | 52 |
53 class IntroDataSource(TemplateDataSource): | 53 class IntroDataSource(TemplateDataSource): |
54 '''Serves templates for Intros. | 54 '''Serves templates for Intros. |
55 ''' | 55 ''' |
56 _BASE = INTROS_TEMPLATES | 56 _BASE = INTROS_TEMPLATES |
57 | 57 |
58 | 58 |
59 class PartialDataSource(TemplateDataSource): | 59 class PartialDataSource(TemplateDataSource): |
60 '''Serves templates for private templates. | 60 '''Serves templates for private templates. |
61 ''' | 61 ''' |
62 _BASE = PRIVATE_TEMPLATES | 62 _BASE = PRIVATE_TEMPLATES |
OLD | NEW |