comparison piecrust/baking/baker.py @ 868:8d25f76fce98

bake: Add ability to specify pipelines to exclude during the bake.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 12 Jun 2017 22:22:19 -0700
parents 448710d84121
children 504ddb370df8
comparison
equal deleted inserted replaced
867:757fba54bfd3 868:8d25f76fce98
24 return records_cache.getCachePath(records_name) 24 return records_cache.getCachePath(records_name)
25 25
26 26
27 class Baker(object): 27 class Baker(object):
28 def __init__(self, appfactory, app, out_dir, 28 def __init__(self, appfactory, app, out_dir,
29 force=False, allowed_pipelines=None): 29 force=False, allowed_pipelines=None,
30 forbidden_pipelines=None):
30 self.appfactory = appfactory 31 self.appfactory = appfactory
31 self.app = app 32 self.app = app
32 self.out_dir = out_dir 33 self.out_dir = out_dir
33 self.force = force 34 self.force = force
34
35 self.allowed_pipelines = allowed_pipelines 35 self.allowed_pipelines = allowed_pipelines
36 if allowed_pipelines is None: 36 self.forbidden_pipelines = forbidden_pipelines
37 self.allowed_pipelines = list(self._pipeline_classes.keys())
38 37
39 def bake(self): 38 def bake(self):
40 start_time = time.perf_counter() 39 start_time = time.perf_counter()
41 logger.debug(" Bake Output: %s" % self.out_dir) 40 logger.debug(" Bake Output: %s" % self.out_dir)
42 logger.debug(" Root URL: %s" % self.app.config.get('site/root')) 41 logger.debug(" Root URL: %s" % self.app.config.get('site/root'))
83 # 82 #
84 # Also, create and initialize each pipeline for each source. 83 # Also, create and initialize each pipeline for each source.
85 has_any_pp = False 84 has_any_pp = False
86 ppmngr = PipelineManager( 85 ppmngr = PipelineManager(
87 self.app, self.out_dir, record_histories) 86 self.app, self.out_dir, record_histories)
87 ok_pp = self.allowed_pipelines
88 nok_pp = self.forbidden_pipelines
88 for source in self.app.sources: 89 for source in self.app.sources:
89 pname = get_pipeline_name_for_source(source) 90 pname = get_pipeline_name_for_source(source)
90 if pname in self.allowed_pipelines: 91 if ok_pp is not None and pname not in ok_pp:
91 ppinfo = ppmngr.createPipeline(source) 92 continue
92 logger.debug( 93 if nok_pp is not None and pname in nok_pp:
93 "Created pipeline '%s' for source: %s" % 94 continue
94 (ppinfo.pipeline.PIPELINE_NAME, source.name)) 95
95 has_any_pp = True 96 ppinfo = ppmngr.createPipeline(source)
96 else: 97 logger.debug(
97 logger.debug( 98 "Created pipeline '%s' for source: %s" %
98 "Skip source '%s' because pipeline '%s' is ignored." % 99 (ppinfo.pipeline.PIPELINE_NAME, source.name))
99 (source.name, pname)) 100 has_any_pp = True
100 if not has_any_pp: 101 if not has_any_pp:
101 raise Exception("The website has no content sources, or the bake " 102 raise Exception("The website has no content sources, or the bake "
102 "command was invoked with all pipelines filtered " 103 "command was invoked with all pipelines filtered "
103 "out. There's nothing to do.") 104 "out. There's nothing to do.")
104 105
282 ctx = BakeWorkerContext( 283 ctx = BakeWorkerContext(
283 self.appfactory, 284 self.appfactory,
284 self.out_dir, 285 self.out_dir,
285 force=self.force, 286 force=self.force,
286 previous_records_path=previous_records_path, 287 previous_records_path=previous_records_path,
287 allowed_pipelines=self.allowed_pipelines) 288 allowed_pipelines=self.allowed_pipelines,
289 forbidden_pipelines=self.forbidden_pipelines)
288 pool = WorkerPool( 290 pool = WorkerPool(
289 worker_count=worker_count, 291 worker_count=worker_count,
290 batch_size=batch_size, 292 batch_size=batch_size,
291 worker_class=BakeWorker, 293 worker_class=BakeWorker,
292 initargs=(ctx,), 294 initargs=(ctx,),