comparison piecrust/pipelines/base.py @ 855:448710d84121

refactor: Get the taxonomy support back to a functional state. There's now a taxonomy content source that wraps another normal content source like a blog posts' source. It works in tandem with a taxonomy content pipeline that will do the heavy lifting of figuring out what kind of terms exist and need to be baked.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 06 Jun 2017 00:26:21 -0700
parents 08e02c2a2a1a
children d1095774bfcf
comparison
equal deleted inserted replaced
854:08e02c2a2a1a 855:448710d84121
40 self.record_name = pipeline.record_name 40 self.record_name = pipeline.record_name
41 self.content_item = content_item 41 self.content_item = content_item
42 self.data = {} 42 self.data = {}
43 43
44 44
45 class PipelineJobCreateContext:
46 """ Context for create pipeline baking jobs.
47 """
48 def __init__(self, pass_num, record_histories):
49 self.pass_num = pass_num
50 self.record_histories = record_histories
51
52
45 class PipelineJobRunContext: 53 class PipelineJobRunContext:
46 """ Context for running pipeline baking jobs. 54 """ Context for running pipeline baking jobs.
47 """ 55 """
48 def __init__(self, job, pipeline, record_histories): 56 def __init__(self, job, pipeline, record_histories):
49 self.record_histories = record_histories 57 self.record_histories = record_histories
73 """ 81 """
74 def __init__(self, record, job, pass_num): 82 def __init__(self, record, job, pass_num):
75 self.record = record 83 self.record = record
76 self.job = job 84 self.job = job
77 self.pass_num = pass_num 85 self.pass_num = pass_num
86
87
88 class PipelinePostJobRunContext:
89 def __init__(self, record_history):
90 self.record_history = record_history
78 91
79 92
80 class PipelineDeletionContext: 93 class PipelineDeletionContext:
81 def __init__(self, record_history): 94 def __init__(self, record_history):
82 self.record_history = record_history 95 self.record_history = record_history
111 return self.source.app 124 return self.source.app
112 125
113 def initialize(self): 126 def initialize(self):
114 pass 127 pass
115 128
116 def createJobs(self): 129 def createJobs(self, ctx):
117 return [ 130 return [
118 self.createJob(item) 131 self.createJob(item)
119 for item in self.source.getAllContents()] 132 for item in self.source.getAllContents()]
120 133
121 def createJob(self, content_item): 134 def createJob(self, content_item):
131 raise NotImplementedError() 144 raise NotImplementedError()
132 145
133 def run(self, job, ctx, result): 146 def run(self, job, ctx, result):
134 raise NotImplementedError() 147 raise NotImplementedError()
135 148
149 def postJobRun(self, ctx):
150 pass
151
136 def getDeletions(self, ctx): 152 def getDeletions(self, ctx):
137 pass 153 pass
138 154
139 def collapseRecords(self, ctx): 155 def collapseRecords(self, ctx):
140 pass 156 pass
141 157
142 def shutdown(self): 158 def shutdown(self):
143 pass 159 pass
160
161
162 def get_record_name_for_source(source):
163 ppname = get_pipeline_name_for_source(source)
164 return '%s@%s' % (source.name, ppname)
144 165
145 166
146 def get_pipeline_name_for_source(source): 167 def get_pipeline_name_for_source(source):
147 pname = source.config['pipeline'] 168 pname = source.config['pipeline']
148 if not pname: 169 if not pname:
189 210
190 info = _PipelineInfo(pp, record_history) 211 info = _PipelineInfo(pp, record_history)
191 self._pipelines[source.name] = info 212 self._pipelines[source.name] = info
192 return info 213 return info
193 214
194 def buildHistoryDiffs(self): 215 def postJobRun(self):
195 for ppinfo in self.getPipelines(): 216 for ppinfo in self.getPipelines():
196 ppinfo.record_history.build() 217 ppinfo.record_history.build()
218
219 for ppinfo in self.getPipelines():
220 ctx = PipelinePostJobRunContext(ppinfo.record_history)
221 ppinfo.pipeline.postJobRun(ctx)
197 222
198 def deleteStaleOutputs(self): 223 def deleteStaleOutputs(self):
199 for ppinfo in self.getPipelines(): 224 for ppinfo in self.getPipelines():
200 ctx = PipelineDeletionContext(ppinfo.record_history) 225 ctx = PipelineDeletionContext(ppinfo.record_history)
201 to_delete = ppinfo.pipeline.getDeletions(ctx) 226 to_delete = ppinfo.pipeline.getDeletions(ctx)