diff piecrust/pipelines/_pagerecords.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 08e02c2a2a1a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/piecrust/pipelines/_pagerecords.py	Wed May 17 00:11:48 2017 -0700
@@ -0,0 +1,103 @@
+import copy
+from piecrust.pipelines.records import RecordEntry
+
+
+class SubPagePipelineRecordEntry:
+    FLAG_NONE = 0
+    FLAG_BAKED = 2**0
+    FLAG_FORCED_BY_SOURCE = 2**1
+    FLAG_FORCED_BY_NO_PREVIOUS = 2**2
+    FLAG_FORCED_BY_PREVIOUS_ERRORS = 2**3
+    FLAG_FORMATTING_INVALIDATED = 2**4
+
+    def __init__(self, out_uri, out_path):
+        self.out_uri = out_uri
+        self.out_path = out_path
+        self.flags = self.FLAG_NONE
+        self.errors = []
+        self.render_info = [None, None]  # Same length as RENDER_PASSES
+
+    @property
+    def was_clean(self):
+        return (self.flags & self.FLAG_BAKED) == 0 and len(self.errors) == 0
+
+    @property
+    def was_baked(self):
+        return (self.flags & self.FLAG_BAKED) != 0
+
+    @property
+    def was_baked_successfully(self):
+        return self.was_baked and len(self.errors) == 0
+
+    def anyPass(self, func):
+        for pinfo in self.render_info:
+            if pinfo and func(pinfo):
+                return True
+        return False
+
+    def copyRenderInfo(self):
+        return copy.deepcopy(self.render_info)
+
+
+class PagePipelineRecordEntry(RecordEntry):
+    FLAG_NONE = 0
+    FLAG_NEW = 2**0
+    FLAG_SOURCE_MODIFIED = 2**1
+    FLAG_OVERRIDEN = 2**2
+
+    def __init__(self):
+        super().__init__()
+        self.flags = self.FLAG_NONE
+        self.config = None
+        self.subs = []
+
+    @property
+    def was_overriden(self):
+        return (self.flags & self.FLAG_OVERRIDEN) != 0
+
+    @property
+    def num_subs(self):
+        return len(self.subs)
+
+    @property
+    def was_any_sub_baked(self):
+        for o in self.subs:
+            if o.was_baked:
+                return True
+        return False
+
+    @property
+    def all_assets(self):
+        for sub in self.subs:
+            yield from sub.assets
+
+    @property
+    def all_out_paths(self):
+        for sub in self.subs:
+            yield sub.out_path
+
+    @property
+    def has_any_error(self):
+        if len(self.errors) > 0:
+            return True
+        for o in self.subs:
+            if len(o.errors) > 0:
+                return True
+        return False
+
+    def getSub(self, page_num):
+        return self.subs[page_num - 1]
+
+    def getAllErrors(self):
+        yield from self.errors
+        for o in self.subs:
+            yield from o.errors
+
+    def getAllUsedSourceNames(self):
+        res = set()
+        for o in self.subs:
+            for pinfo in o.render_info:
+                if pinfo:
+                    res |= pinfo.used_source_names
+        return res
+