diff piecrust/pipelines/base.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
children f070a4fc033c
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/piecrust/pipelines/base.py	Wed May 17 00:11:48 2017 -0700
@@ -0,0 +1,73 @@
+import os.path
+import logging
+
+
+logger = logging.getLogger(__name__)
+
+
+class PipelineContext:
+    """ The context for running a content pipeline.
+    """
+    def __init__(self, out_dir, record_history, *,
+                 worker_id=-1, force=None):
+        self.out_dir = out_dir
+        self.record_history = record_history
+        self.worker_id = worker_id
+        self.force = force
+
+    @property
+    def is_worker(self):
+        """ Returns `True` if the content pipeline is running inside
+            a worker process, and this is the first one.
+        """
+        return self.worker_id >= 0
+
+    @property
+    def is_main_process(self):
+        """ Returns `True` is the content pipeline is running inside
+            the main process (and not a worker process). This is the case
+            if there are no worker processes at all.
+        """
+        return self.worker_id < 0
+
+
+class PipelineResult:
+    def __init__(self, record):
+        self.record = record
+
+
+class ContentPipeline:
+    """ A pipeline that processes content from a `ContentSource`.
+    """
+    PIPELINE_NAME = None
+    PIPELINE_PASSES = 1
+    RECORD_CLASS = None
+
+    def __init__(self, source):
+        self.source = source
+
+        app = source.app
+        tmp_dir = app.cache_dir
+        if not tmp_dir:
+            import tempfile
+            tmp_dir = os.path.join(tempfile.gettempdir(), 'piecrust')
+        self.tmp_dir = os.path.join(tmp_dir, self.PIPELINE_NAME)
+
+    @property
+    def app(self):
+        return self.source.app
+
+    def initialize(self, ctx):
+        pass
+
+    def run(self, content_item, ctx, result):
+        raise NotImplementedError()
+
+    def shutdown(self, ctx):
+        pass
+
+    def collapseRecords(self, record_history):
+        pass
+
+    def getDeletions(self, record_history):
+        pass