Mercurial > piecrust2
changeset 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 | 757fba54bfd3 |
children | 41b0c94f9833 |
files | piecrust/baking/baker.py piecrust/baking/worker.py piecrust/commands/builtin/baking.py |
diffstat | 3 files changed, 34 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/baking/baker.py Mon Jun 12 22:20:58 2017 -0700 +++ b/piecrust/baking/baker.py Mon Jun 12 22:22:19 2017 -0700 @@ -26,15 +26,14 @@ class Baker(object): def __init__(self, appfactory, app, out_dir, - force=False, allowed_pipelines=None): + force=False, allowed_pipelines=None, + forbidden_pipelines=None): self.appfactory = appfactory self.app = app self.out_dir = out_dir self.force = force - self.allowed_pipelines = allowed_pipelines - if allowed_pipelines is None: - self.allowed_pipelines = list(self._pipeline_classes.keys()) + self.forbidden_pipelines = forbidden_pipelines def bake(self): start_time = time.perf_counter() @@ -85,18 +84,20 @@ has_any_pp = False ppmngr = PipelineManager( self.app, self.out_dir, record_histories) + ok_pp = self.allowed_pipelines + nok_pp = self.forbidden_pipelines for source in self.app.sources: pname = get_pipeline_name_for_source(source) - if pname in self.allowed_pipelines: - ppinfo = ppmngr.createPipeline(source) - logger.debug( - "Created pipeline '%s' for source: %s" % - (ppinfo.pipeline.PIPELINE_NAME, source.name)) - has_any_pp = True - else: - logger.debug( - "Skip source '%s' because pipeline '%s' is ignored." % - (source.name, pname)) + if ok_pp is not None and pname not in ok_pp: + continue + if nok_pp is not None and pname in nok_pp: + continue + + ppinfo = ppmngr.createPipeline(source) + logger.debug( + "Created pipeline '%s' for source: %s" % + (ppinfo.pipeline.PIPELINE_NAME, source.name)) + has_any_pp = True if not has_any_pp: raise Exception("The website has no content sources, or the bake " "command was invoked with all pipelines filtered " @@ -284,7 +285,8 @@ self.out_dir, force=self.force, previous_records_path=previous_records_path, - allowed_pipelines=self.allowed_pipelines) + allowed_pipelines=self.allowed_pipelines, + forbidden_pipelines=self.forbidden_pipelines) pool = WorkerPool( worker_count=worker_count, batch_size=batch_size,
--- a/piecrust/baking/worker.py Mon Jun 12 22:20:58 2017 -0700 +++ b/piecrust/baking/worker.py Mon Jun 12 22:22:19 2017 -0700 @@ -14,12 +14,13 @@ class BakeWorkerContext(object): def __init__(self, appfactory, out_dir, *, force=False, previous_records_path=None, - allowed_pipelines=None): + allowed_pipelines=None, forbidden_pipelines=None): self.appfactory = appfactory self.out_dir = out_dir self.force = force self.previous_records_path = previous_records_path self.allowed_pipelines = allowed_pipelines + self.forbidden_pipelines = forbidden_pipelines class BakeWorker(IWorker): @@ -59,10 +60,13 @@ self.ppmngr = PipelineManager( app, self.ctx.out_dir, self.record_histories, worker_id=self.wid, force=self.ctx.force) + ok_pp = self.ctx.allowed_pipelines + nok_pp = self.ctx.forbidden_pipelines for src in app.sources: pname = get_pipeline_name_for_source(src) - if (self.ctx.allowed_pipelines is not None and - pname not in self.ctx.allowed_pipelines): + if ok_pp is not None and pname not in ok_pp: + continue + if nok_pp is not None and pname in nok_pp: continue self.ppmngr.createPipeline(src)
--- a/piecrust/commands/builtin/baking.py Mon Jun 12 22:20:58 2017 -0700 +++ b/piecrust/commands/builtin/baking.py Mon Jun 12 22:22:19 2017 -0700 @@ -88,21 +88,27 @@ ctx.app.config.set('baker/batch_size', ctx.args.batch_size) allowed_pipelines = None + forbidden_pipelines = None if ctx.args.html_only: - allowed_pipelines = ['page'] + forbidden_pipelines = ['asset'] elif ctx.args.assets_only: allowed_pipelines = ['asset'] elif ctx.args.pipelines: - if allowed_pipelines: + if allowed_pipelines or forbidden_pipelines: raise Exception( "Can't specify `--html-only` or `--assets-only` with " "`--pipelines`.") - allowed_pipelines = ctx.args.pipelines + for p in ctx.args.pipelines: + if p[0] == '-': + forbidden_pipelines.append(p) + else: + allowed_pipelines.append(p) baker = Baker( ctx.appfactory, ctx.app, out_dir, force=ctx.args.force, - allowed_pipelines=allowed_pipelines) + allowed_pipelines=allowed_pipelines, + forbidden_pipelines=forbidden_pipelines) records = baker.bake() return records