view piecrust/sources/generator.py @ 1136:5f97b5b59dfe

bake: Optimize cache handling for the baking process. - Get rid of the 2-level pipeline runs... handle a single set of passes. - Go back to load/render segments/layout passes for pages. - Add descriptions of what each job batch does. - Improve the taxonomy pipeline so it doesn't re-bake terms that don't need to be re-baked. - Simplify some of the code.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 23 Apr 2018 21:47:49 -0700
parents d1095774bfcf
children
line wrap: on
line source

import io
import time
from werkzeug.utils import cached_property
from piecrust.configuration import ConfigurationError
from piecrust.sources.base import ContentSource, GeneratedContentException


class GeneratorSourceBase(ContentSource):
    def __init__(self, app, name, config):
        super().__init__(app, name, config)

        source_name = config.get('source')
        if source_name is None:
            raise ConfigurationError(
                "Taxonomy source '%s' requires an inner source." % name)
        self._inner_source_name = source_name

        self._raw_item = ''
        self._raw_item_time = time.time()

    @cached_property
    def inner_source(self):
        return self.app.getSource(self._inner_source_name)

    def getContents(self, group):
        # Our content is procedurally generated from other content sources,
        # so we really don't support listing anything here -- it would be
        # typically quite costly.
        raise GeneratedContentException()

    def openItem(self, item, mode='r', **kwargs):
        return io.StringIO(self._raw_item)

    def getItemMtime(self, item):
        return self._raw_item_time