Mercurial > piecrust2
comparison piecrust/data/pagedata.py @ 711:ab5c6a8ae90a
bake: Replace hard-coded taxonomy support with "generator" system.
* Taxonomies are now implemented one or more `TaxonomyGenerator`s.
* A `BlogArchivesGenerator` stub is there but non-functional.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 26 May 2016 19:52:47 -0700 |
parents | 785dea918ad8 |
children | aed8a860c1d0 |
comparison
equal
deleted
inserted
replaced
710:e85f29b28b84 | 711:ab5c6a8ae90a |
---|---|
1 import time | 1 import time |
2 import logging | |
2 import collections.abc | 3 import collections.abc |
4 | |
5 | |
6 logger = logging.getLogger(__name__) | |
3 | 7 |
4 | 8 |
5 class LazyPageConfigLoaderHasNoValue(Exception): | 9 class LazyPageConfigLoaderHasNoValue(Exception): |
6 """ An exception that can be returned when a loader for `LazyPageConfig` | 10 """ An exception that can be returned when a loader for `LazyPageConfig` |
7 can't return any value. | 11 can't return any value. |
27 | 31 |
28 def __getattr__(self, name): | 32 def __getattr__(self, name): |
29 try: | 33 try: |
30 return self._getValue(name) | 34 return self._getValue(name) |
31 except LazyPageConfigLoaderHasNoValue as ex: | 35 except LazyPageConfigLoaderHasNoValue as ex: |
36 logger.exception(ex) | |
32 raise AttributeError("No such attribute: %s" % name) from ex | 37 raise AttributeError("No such attribute: %s" % name) from ex |
33 | 38 |
34 def __getitem__(self, name): | 39 def __getitem__(self, name): |
35 try: | 40 try: |
36 return self._getValue(name) | 41 return self._getValue(name) |
37 except LazyPageConfigLoaderHasNoValue as ex: | 42 except LazyPageConfigLoaderHasNoValue as ex: |
43 logger.exception(ex) | |
38 raise KeyError("No such key: %s" % name) from ex | 44 raise KeyError("No such key: %s" % name) from ex |
39 | 45 |
40 def __iter__(self): | 46 def __iter__(self): |
41 keys = set(self._page.config.keys()) | 47 keys = set(self._page.config.keys()) |
42 keys |= set(self._values.keys()) | 48 keys |= set(self._values.keys()) |
67 try: | 73 try: |
68 self._values[name] = loader(self, name) | 74 self._values[name] = loader(self, name) |
69 except LazyPageConfigLoaderHasNoValue: | 75 except LazyPageConfigLoaderHasNoValue: |
70 raise | 76 raise |
71 except Exception as ex: | 77 except Exception as ex: |
78 logger.exception(ex) | |
72 raise Exception( | 79 raise Exception( |
73 "Error while loading attribute '%s' for: %s" % | 80 "Error while loading attribute '%s' for: %s" % |
74 (name, self._page.rel_path)) from ex | 81 (name, self._page.rel_path)) from ex |
75 | 82 |
76 # Forget this loader now that it served its purpose. | 83 # Forget this loader now that it served its purpose. |
86 try: | 93 try: |
87 self._values[name] = loader(self, name) | 94 self._values[name] = loader(self, name) |
88 except LazyPageConfigLoaderHasNoValue: | 95 except LazyPageConfigLoaderHasNoValue: |
89 raise | 96 raise |
90 except Exception as ex: | 97 except Exception as ex: |
98 logger.exception(ex) | |
91 raise Exception( | 99 raise Exception( |
92 "Error while loading attribute '%s' for: %s" % | 100 "Error while loading attribute '%s' for: %s" % |
93 (name, self._page.rel_path)) from ex | 101 (name, self._page.rel_path)) from ex |
94 # We always keep the wildcard loader in the loaders list. | 102 # We always keep the wildcard loader in the loaders list. |
95 return self._values[name] | 103 return self._values[name] |
123 | 131 |
124 self._is_loaded = True | 132 self._is_loaded = True |
125 try: | 133 try: |
126 self._load() | 134 self._load() |
127 except Exception as ex: | 135 except Exception as ex: |
136 logger.exception(ex) | |
128 raise Exception( | 137 raise Exception( |
129 "Error while loading data for: %s" % | 138 "Error while loading data for: %s" % |
130 self._page.rel_path) from ex | 139 self._page.rel_path) from ex |
131 | 140 |
132 def _load(self): | 141 def _load(self): |