comparison piecrust/pipelines/base.py @ 852:4850f8c21b6e

core: Start of the big refactor for PieCrust 3.0. * Everything is a `ContentSource`, including assets directories. * Most content sources are subclasses of the base file-system source. * A source is processed by a "pipeline", and there are 2 built-in pipelines, one for assets and one for pages. The asset pipeline is vaguely functional, but the page pipeline is completely broken right now. * Rewrite the baking process as just running appropriate pipelines on each content item. This should allow for better parallelization.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 17 May 2017 00:11:48 -0700
parents
children f070a4fc033c
comparison
equal deleted inserted replaced
851:2c7e57d80bba 852:4850f8c21b6e
1 import os.path
2 import logging
3
4
5 logger = logging.getLogger(__name__)
6
7
8 class PipelineContext:
9 """ The context for running a content pipeline.
10 """
11 def __init__(self, out_dir, record_history, *,
12 worker_id=-1, force=None):
13 self.out_dir = out_dir
14 self.record_history = record_history
15 self.worker_id = worker_id
16 self.force = force
17
18 @property
19 def is_worker(self):
20 """ Returns `True` if the content pipeline is running inside
21 a worker process, and this is the first one.
22 """
23 return self.worker_id >= 0
24
25 @property
26 def is_main_process(self):
27 """ Returns `True` is the content pipeline is running inside
28 the main process (and not a worker process). This is the case
29 if there are no worker processes at all.
30 """
31 return self.worker_id < 0
32
33
34 class PipelineResult:
35 def __init__(self, record):
36 self.record = record
37
38
39 class ContentPipeline:
40 """ A pipeline that processes content from a `ContentSource`.
41 """
42 PIPELINE_NAME = None
43 PIPELINE_PASSES = 1
44 RECORD_CLASS = None
45
46 def __init__(self, source):
47 self.source = source
48
49 app = source.app
50 tmp_dir = app.cache_dir
51 if not tmp_dir:
52 import tempfile
53 tmp_dir = os.path.join(tempfile.gettempdir(), 'piecrust')
54 self.tmp_dir = os.path.join(tmp_dir, self.PIPELINE_NAME)
55
56 @property
57 def app(self):
58 return self.source.app
59
60 def initialize(self, ctx):
61 pass
62
63 def run(self, content_item, ctx, result):
64 raise NotImplementedError()
65
66 def shutdown(self, ctx):
67 pass
68
69 def collapseRecords(self, record_history):
70 pass
71
72 def getDeletions(self, record_history):
73 pass