| 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 from HTMLParser import HTMLParser | 5 from HTMLParser import HTMLParser |
| 6 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 | 9 |
| 10 from data_source import DataSource | 10 from data_source import DataSource |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 self._cache = server_instance.compiled_fs_factory.Create( | 29 self._cache = server_instance.compiled_fs_factory.Create( |
| 30 server_instance.host_file_system_provider.GetTrunk(), | 30 server_instance.host_file_system_provider.GetTrunk(), |
| 31 self._MakeIntro, | 31 self._MakeIntro, |
| 32 IntroDataSource) | 32 IntroDataSource) |
| 33 self._ref_resolver = server_instance.ref_resolver_factory.Create() | 33 self._ref_resolver = server_instance.ref_resolver_factory.Create() |
| 34 | 34 |
| 35 def _MakeIntro(self, intro_path, intro): | 35 def _MakeIntro(self, intro_path, intro): |
| 36 # Guess the name of the API from the path to the intro. | 36 # Guess the name of the API from the path to the intro. |
| 37 api_name = os.path.splitext(intro_path.split('/')[-1])[0] | 37 api_name = os.path.splitext(intro_path.split('/')[-1])[0] |
| 38 return Handlebar( | 38 return Handlebar( |
| 39 self._ref_resolver.ResolveAllLinks(intro, namespace=api_name), | 39 self._ref_resolver.ResolveAllLinks(intro, |
| 40 relative_to=self._request.path, |
| 41 namespace=api_name), |
| 40 name=intro_path) | 42 name=intro_path) |
| 41 | 43 |
| 42 def get(self, key): | 44 def get(self, key): |
| 43 path = FormatKey(key) | 45 path = FormatKey(key) |
| 44 def get_from_base_path(base_path): | 46 def get_from_base_path(base_path): |
| 45 return self._cache.GetFromFile('%s/%s' % (base_path, path)).Get() | 47 return self._cache.GetFromFile('%s/%s' % (base_path, path)).Get() |
| 46 base_paths = (INTROS_TEMPLATES, ARTICLES_TEMPLATES) | 48 base_paths = (INTROS_TEMPLATES, ARTICLES_TEMPLATES) |
| 47 for base_path in base_paths: | 49 for base_path in base_paths: |
| 48 try: | 50 try: |
| 49 return get_from_base_path(base_path) | 51 return get_from_base_path(base_path) |
| 50 except FileNotFoundError: | 52 except FileNotFoundError: |
| 51 continue | 53 continue |
| 52 # Not found. Do the first operation again so that we get a stack trace - we | 54 # Not found. Do the first operation again so that we get a stack trace - we |
| 53 # know that it'll fail. | 55 # know that it'll fail. |
| 54 get_from_base_path(base_paths[0]) | 56 get_from_base_path(base_paths[0]) |
| 55 raise AssertionError() | 57 raise AssertionError() |
| 56 | 58 |
| 57 def Cron(self): | 59 def Cron(self): |
| 58 # TODO(kalman): Walk through the intros and articles directory. | 60 # TODO(kalman): Walk through the intros and articles directory. |
| 59 return Future(value=()) | 61 return Future(value=()) |
| OLD | NEW |