| 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 copy | 5 import copy |
| 6 import logging | 6 import logging |
| 7 | 7 |
| 8 from compiled_file_system import SingleFile | 8 from compiled_file_system import SingleFile |
| 9 from data_source import DataSource | 9 from data_source import DataSource |
| 10 from extensions_paths import JSON_TEMPLATES |
| 10 from future import Gettable, Future | 11 from future import Gettable, Future |
| 11 from third_party.json_schema_compiler.json_parse import Parse | 12 from third_party.json_schema_compiler.json_parse import Parse |
| 12 from svn_constants import JSON_PATH | |
| 13 | 13 |
| 14 | 14 |
| 15 def _AddLevels(items, level): | 15 def _AddLevels(items, level): |
| 16 '''Add a 'level' key to each item in |items|. 'level' corresponds to how deep | 16 '''Add a 'level' key to each item in |items|. 'level' corresponds to how deep |
| 17 in |items| an item is. |level| sets the starting depth. | 17 in |items| an item is. |level| sets the starting depth. |
| 18 ''' | 18 ''' |
| 19 for item in items: | 19 for item in items: |
| 20 item['level'] = level | 20 item['level'] = level |
| 21 if 'items' in item: | 21 if 'items' in item: |
| 22 _AddLevels(item['items'], level + 1) | 22 _AddLevels(item['items'], level + 1) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 href = item.get('href') | 71 href = item.get('href') |
| 72 if href is not None and not href.startswith(('http://', 'https://')): | 72 if href is not None and not href.startswith(('http://', 'https://')): |
| 73 if not href.startswith('/'): | 73 if not href.startswith('/'): |
| 74 logging.warn('Paths in sidenav must be qualified. %s is not.' % href) | 74 logging.warn('Paths in sidenav must be qualified. %s is not.' % href) |
| 75 else: | 75 else: |
| 76 href = href.lstrip('/') | 76 href = href.lstrip('/') |
| 77 item['href'] = self._server_instance.base_path + href | 77 item['href'] = self._server_instance.base_path + href |
| 78 | 78 |
| 79 def Cron(self): | 79 def Cron(self): |
| 80 futures = [ | 80 futures = [self._cache.GetFromFile('%s/%s_sidenav.json' % |
| 81 self._cache.GetFromFile('%s/%s_sidenav.json' % (JSON_PATH, platform)) | 81 (JSON_TEMPLATES, platform)) |
| 82 for platform in ('apps', 'extensions')] | 82 for platform in ('apps', 'extensions')] |
| 83 return Future(delegate=Gettable(lambda: [f.Get() for f in futures])) | 83 return Future(delegate=Gettable(lambda: [f.Get() for f in futures])) |
| 84 | 84 |
| 85 def get(self, key): | 85 def get(self, key): |
| 86 sidenav = copy.deepcopy(self._cache.GetFromFile( | 86 sidenav = copy.deepcopy(self._cache.GetFromFile( |
| 87 '%s/%s_sidenav.json' % (JSON_PATH, key)).Get()) | 87 '%s/%s_sidenav.json' % (JSON_TEMPLATES, key)).Get()) |
| 88 _AddSelected(sidenav, self._server_instance.base_path + self._request.path) | 88 _AddSelected(sidenav, self._server_instance.base_path + self._request.path) |
| 89 return sidenav | 89 return sidenav |
| OLD | NEW |