Mercurial > piecrust2
comparison piecrust/data/iterators.py @ 852:4850f8c21b6e
core: Start of the big refactor for PieCrust 3.0.
* Everything is a `ContentSource`, including assets directories.
* Most content sources are subclasses of the base file-system source.
* A source is processed by a "pipeline", and there are 2 built-in pipelines,
one for assets and one for pages. The asset pipeline is vaguely functional,
but the page pipeline is completely broken right now.
* Rewrite the baking process as just running appropriate pipelines on each
content item. This should allow for better parallelization.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 17 May 2017 00:11:48 -0700 |
parents | e35407c60e00 |
children |
comparison
equal
deleted
inserted
replaced
851:2c7e57d80bba | 852:4850f8c21b6e |
---|---|
1 import logging | 1 import logging |
2 from piecrust.data.filters import PaginationFilter, IsFilterClause, NotClause | 2 from piecrust.data.filters import PaginationFilter |
3 from piecrust.environment import AbortedSourceUseError | |
4 from piecrust.events import Event | 3 from piecrust.events import Event |
5 from piecrust.sources.base import PageSource | 4 from piecrust.sources.base import ContentSource, AbortedSourceUseError |
6 from piecrust.sources.interfaces import IPaginationSource | 5 from piecrust.sources.interfaces import IPaginationSource |
7 | 6 |
8 | 7 |
9 logger = logging.getLogger(__name__) | 8 logger = logging.getLogger(__name__) |
10 | 9 |
144 if isinstance(source, IPaginationSource): | 143 if isinstance(source, IPaginationSource): |
145 src_it = source.getSourceIterator() | 144 src_it = source.getSourceIterator() |
146 if src_it is not None: | 145 if src_it is not None: |
147 self._pages = src_it | 146 self._pages = src_it |
148 | 147 |
149 # If we're currently baking, apply the default baker filter | |
150 # to exclude things like draft posts. | |
151 if (isinstance(source, PageSource) and | |
152 source.app.config.get('baker/is_baking')): | |
153 setting_name = source.app.config.get('baker/no_bake_setting', | |
154 'draft') | |
155 accessor = self._getSettingAccessor() | |
156 draft_filter = PaginationFilter(accessor) | |
157 draft_filter.root_clause = NotClause() | |
158 draft_filter.root_clause.addClause( | |
159 IsFilterClause(setting_name, True)) | |
160 self._simpleNonSortedWrap( | |
161 PaginationFilterIterator, draft_filter) | |
162 | |
163 # Apply any filter first, before we start sorting or slicing. | 148 # Apply any filter first, before we start sorting or slicing. |
164 if pagination_filter is not None: | 149 if pagination_filter is not None: |
165 self._simpleNonSortedWrap(PaginationFilterIterator, | 150 self._simpleNonSortedWrap(PaginationFilterIterator, |
166 pagination_filter) | 151 pagination_filter) |
167 | 152 |
323 if self._pagesData is not None: | 308 if self._pagesData is not None: |
324 return | 309 return |
325 | 310 |
326 if (self._current_page is not None and | 311 if (self._current_page is not None and |
327 self._current_page.app.env.abort_source_use and | 312 self._current_page.app.env.abort_source_use and |
328 isinstance(self._source, PageSource)): | 313 isinstance(self._source, ContentSource)): |
329 logger.debug("Aborting iteration from %s." % | 314 logger.debug("Aborting iteration from %s." % |
330 self._current_page.ref_spec) | 315 self._current_page.ref_spec) |
331 raise AbortedSourceUseError() | 316 raise AbortedSourceUseError() |
332 | 317 |
333 self._ensureSorter() | 318 self._ensureSorter() |