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 json | 6 import json |
7 import logging | 7 import logging |
8 | 8 |
9 import compiled_file_system as compiled_fs | 9 import compiled_file_system as compiled_fs |
10 from file_system import FileNotFoundError | |
11 from third_party.json_schema_compiler.model import UnixName | 10 from third_party.json_schema_compiler.model import UnixName |
12 | 11 |
13 # Increment this if the data model changes for SidenavDataSource. | 12 # Increment this if the data model changes for SidenavDataSource. |
14 _VERSION = 1 | 13 _VERSION = 1 |
15 | 14 |
16 class SidenavDataSource(object): | 15 class SidenavDataSource(object): |
17 """This class reads in and caches a JSON file representing the side navigation | 16 """This class reads in and caches a JSON file representing the side navigation |
18 menu. | 17 menu. |
19 """ | 18 """ |
20 class Factory(object): | 19 class Factory(object): |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 if item.get('fileName', '') == self._file_name: | 54 if item.get('fileName', '') == self._file_name: |
56 item['selected'] = True | 55 item['selected'] = True |
57 return True | 56 return True |
58 if 'items' in item: | 57 if 'items' in item: |
59 if self._AddSelected(item['items']): | 58 if self._AddSelected(item['items']): |
60 item['child_selected'] = True | 59 item['child_selected'] = True |
61 return True | 60 return True |
62 return False | 61 return False |
63 | 62 |
64 def get(self, key): | 63 def get(self, key): |
65 try: | 64 sidenav = copy.deepcopy(self._cache.GetFromFile( |
66 sidenav = copy.deepcopy(self._cache.GetFromFile( | 65 '%s/%s_sidenav.json' % (self._json_path, key))) |
67 '%s/%s_sidenav.json' % (self._json_path, key))) | 66 self._AddSelected(sidenav) |
68 self._AddSelected(sidenav) | 67 return sidenav |
69 return sidenav | |
70 except FileNotFoundError as e: | |
71 logging.error('%s: Error reading sidenav "%s".' % (e, key)) | |
OLD | NEW |