Mercurial > piecrust2
comparison piecrust/pipelines/_pagerecords.py @ 854:08e02c2a2a1a
core: Keep refactoring, this time to prepare for generator sources.
- Make a few APIs simpler.
- Content pipelines create their own jobs, so that generator sources can
keep aborting in `getContents`, but rely on their pipeline to generate
pages for baking.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 04 Jun 2017 23:34:28 -0700 |
parents | 4850f8c21b6e |
children | 504ddb370df8 |
comparison
equal
deleted
inserted
replaced
853:f070a4fc033c | 854:08e02c2a2a1a |
---|---|
1 import copy | 1 import copy |
2 from piecrust.pipelines.records import RecordEntry | 2 from piecrust.pipelines.records import RecordEntry, get_flag_descriptions |
3 | 3 |
4 | 4 |
5 class SubPagePipelineRecordEntry: | 5 class SubPagePipelineRecordEntry: |
6 FLAG_NONE = 0 | 6 FLAG_NONE = 0 |
7 FLAG_BAKED = 2**0 | 7 FLAG_BAKED = 2**0 |
42 class PagePipelineRecordEntry(RecordEntry): | 42 class PagePipelineRecordEntry(RecordEntry): |
43 FLAG_NONE = 0 | 43 FLAG_NONE = 0 |
44 FLAG_NEW = 2**0 | 44 FLAG_NEW = 2**0 |
45 FLAG_SOURCE_MODIFIED = 2**1 | 45 FLAG_SOURCE_MODIFIED = 2**1 |
46 FLAG_OVERRIDEN = 2**2 | 46 FLAG_OVERRIDEN = 2**2 |
47 FLAG_COLLAPSED_FROM_LAST_RUN = 2**3 | |
47 | 48 |
48 def __init__(self): | 49 def __init__(self): |
49 super().__init__() | 50 super().__init__() |
50 self.flags = self.FLAG_NONE | 51 self.flags = self.FLAG_NONE |
51 self.config = None | 52 self.config = None |
52 self.subs = [] | 53 self.subs = [] |
54 | |
55 @property | |
56 def was_touched(self): | |
57 return (self.flags & self.FLAG_SOURCE_MODIFIED) != 0 | |
53 | 58 |
54 @property | 59 @property |
55 def was_overriden(self): | 60 def was_overriden(self): |
56 return (self.flags & self.FLAG_OVERRIDEN) != 0 | 61 return (self.flags & self.FLAG_OVERRIDEN) != 0 |
57 | 62 |
63 def was_any_sub_baked(self): | 68 def was_any_sub_baked(self): |
64 for o in self.subs: | 69 for o in self.subs: |
65 if o.was_baked: | 70 if o.was_baked: |
66 return True | 71 return True |
67 return False | 72 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 | 73 |
79 @property | 74 @property |
80 def has_any_error(self): | 75 def has_any_error(self): |
81 if len(self.errors) > 0: | 76 if len(self.errors) > 0: |
82 return True | 77 return True |
99 for pinfo in o.render_info: | 94 for pinfo in o.render_info: |
100 if pinfo: | 95 if pinfo: |
101 res |= pinfo.used_source_names | 96 res |= pinfo.used_source_names |
102 return res | 97 return res |
103 | 98 |
99 def getAllOutputPaths(self): | |
100 for o in self.subs: | |
101 yield o.out_path | |
102 | |
103 def describe(self): | |
104 d = super().describe() | |
105 d['Flags'] = get_flag_descriptions(self.flags, flag_descriptions) | |
106 for i, sub in enumerate(self.subs): | |
107 d['Sub%02d' % i] = { | |
108 'URI': sub.out_uri, | |
109 'Path': sub.out_path, | |
110 'Flags': get_flag_descriptions( | |
111 sub.flags, sub_flag_descriptions) | |
112 } | |
113 return d | |
114 | |
115 | |
116 flag_descriptions = { | |
117 PagePipelineRecordEntry.FLAG_NEW: 'new', | |
118 PagePipelineRecordEntry.FLAG_SOURCE_MODIFIED: 'touched', | |
119 PagePipelineRecordEntry.FLAG_OVERRIDEN: 'overriden', | |
120 PagePipelineRecordEntry.FLAG_COLLAPSED_FROM_LAST_RUN: 'from last run'} | |
121 | |
122 | |
123 sub_flag_descriptions = { | |
124 SubPagePipelineRecordEntry.FLAG_BAKED: 'baked', | |
125 SubPagePipelineRecordEntry.FLAG_FORCED_BY_SOURCE: 'forced by source', | |
126 SubPagePipelineRecordEntry.FLAG_FORCED_BY_NO_PREVIOUS: 'forced b/c new', | |
127 SubPagePipelineRecordEntry.FLAG_FORCED_BY_PREVIOUS_ERRORS: | |
128 'forced by errors', | |
129 SubPagePipelineRecordEntry.FLAG_FORMATTING_INVALIDATED: | |
130 'formatting invalidated' | |
131 } |