comparison 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
comparison
equal deleted inserted replaced
851:2c7e57d80bba 852:4850f8c21b6e
1 import copy
2 from piecrust.pipelines.records import RecordEntry
3
4
5 class SubPagePipelineRecordEntry:
6 FLAG_NONE = 0
7 FLAG_BAKED = 2**0
8 FLAG_FORCED_BY_SOURCE = 2**1
9 FLAG_FORCED_BY_NO_PREVIOUS = 2**2
10 FLAG_FORCED_BY_PREVIOUS_ERRORS = 2**3
11 FLAG_FORMATTING_INVALIDATED = 2**4
12
13 def __init__(self, out_uri, out_path):
14 self.out_uri = out_uri
15 self.out_path = out_path
16 self.flags = self.FLAG_NONE
17 self.errors = []
18 self.render_info = [None, None] # Same length as RENDER_PASSES
19
20 @property
21 def was_clean(self):
22 return (self.flags & self.FLAG_BAKED) == 0 and len(self.errors) == 0
23
24 @property
25 def was_baked(self):
26 return (self.flags & self.FLAG_BAKED) != 0
27
28 @property
29 def was_baked_successfully(self):
30 return self.was_baked and len(self.errors) == 0
31
32 def anyPass(self, func):
33 for pinfo in self.render_info:
34 if pinfo and func(pinfo):
35 return True
36 return False
37
38 def copyRenderInfo(self):
39 return copy.deepcopy(self.render_info)
40
41
42 class PagePipelineRecordEntry(RecordEntry):
43 FLAG_NONE = 0
44 FLAG_NEW = 2**0
45 FLAG_SOURCE_MODIFIED = 2**1
46 FLAG_OVERRIDEN = 2**2
47
48 def __init__(self):
49 super().__init__()
50 self.flags = self.FLAG_NONE
51 self.config = None
52 self.subs = []
53
54 @property
55 def was_overriden(self):
56 return (self.flags & self.FLAG_OVERRIDEN) != 0
57
58 @property
59 def num_subs(self):
60 return len(self.subs)
61
62 @property
63 def was_any_sub_baked(self):
64 for o in self.subs:
65 if o.was_baked:
66 return True
67 return False
68
69 @property
70 def all_assets(self):
71 for sub in self.subs:
72 yield from sub.assets
73
74 @property
75 def all_out_paths(self):
76 for sub in self.subs:
77 yield sub.out_path
78
79 @property
80 def has_any_error(self):
81 if len(self.errors) > 0:
82 return True
83 for o in self.subs:
84 if len(o.errors) > 0:
85 return True
86 return False
87
88 def getSub(self, page_num):
89 return self.subs[page_num - 1]
90
91 def getAllErrors(self):
92 yield from self.errors
93 for o in self.subs:
94 yield from o.errors
95
96 def getAllUsedSourceNames(self):
97 res = set()
98 for o in self.subs:
99 for pinfo in o.render_info:
100 if pinfo:
101 res |= pinfo.used_source_names
102 return res
103