Mercurial > piecrust2
view piecrust/processing/base.py @ 853:f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
The asset pipeline is still the only function pipeline at this point.
* No more `QualifiedPage`, and several other pieces of code deleted.
* Data providers are simpler and more focused. For instance, the page iterator
doesn't try to support other types of items.
* Route parameters are proper known source metadata to remove the confusion
between the two.
* Make the baker and pipeline more correctly manage records and record
histories.
* Add support for record collapsing and deleting stale outputs in the asset
pipeline.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 21 May 2017 00:06:59 -0700 |
parents | 4850f8c21b6e |
children | 08e02c2a2a1a |
line wrap: on
line source
import os.path import logging logger = logging.getLogger(__name__) PRIORITY_FIRST = -1 PRIORITY_NORMAL = 0 PRIORITY_LAST = 1 FORCE_BUILD = object() class ProcessorContext: def __init__(self, pipeline, pipeline_ctx): self.ignore_patterns = [] self.extra_processors = [] self._pipeline = pipeline self._pipeline_ctx = pipeline_ctx @property def tmp_dir(self): return self._pipeline.tmp_dir @property def out_dir(self): return self._pipeline_ctx.out_dir @property def worker_id(self): return self._pipeline_ctx.worker_id @property def is_main_process(self): return self._pipeline_ctx.is_main_process class Processor(object): PROCESSOR_NAME = None def __init__(self): self.priority = PRIORITY_NORMAL self.is_bypassing_structured_processing = False self.is_delegating_dependency_check = True def initialize(self, app): self.app = app def onPipelineStart(self, ctx): pass def onPipelineEnd(self, ctx): pass def matches(self, path): return False def getDependencies(self, path): return None def getOutputFilenames(self, filename): return None def process(self, path, out_dir): pass class ExternalProcessException(Exception): def __init__(self, stderr_data): self.stderr_data = stderr_data def __str__(self): return self.stderr_data class SimpleFileProcessor(Processor): def __init__(self, extensions=None): super(SimpleFileProcessor, self).__init__() self.extensions = extensions or {} def matches(self, path): for ext in self.extensions: if path.endswith('.' + ext): return True return False def getOutputFilenames(self, filename): basename, ext = os.path.splitext(filename) ext = ext.lstrip('.') out_ext = self.extensions[ext] return ['%s.%s' % (basename, out_ext)] def process(self, path, out_dir): _, in_name = os.path.split(path) out_name = self.getOutputFilenames(in_name)[0] out_path = os.path.join(out_dir, out_name) return self._doProcess(path, out_path) def _doProcess(self, in_path, out_path): raise NotImplementedError()