Mercurial > piecrust2
comparison piecrust/baking/baker.py @ 918:7f1da7e7b154
internal: The processing loop for the server is now using the baker.
Instead of reimplementing a custom way to run the pipelines, the loop is
just calling the baker, but only for asset pipelines.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 29 Sep 2017 08:43:34 -0700 |
parents | e52e2dd08c96 |
children | bbf5a96b56db |
comparison
equal
deleted
inserted
replaced
917:33a89139c284 | 918:7f1da7e7b154 |
---|---|
23 records_name = '%s%s.records' % (records_id, suffix) | 23 records_name = '%s%s.records' % (records_id, suffix) |
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, |
30 forbidden_pipelines=None): | 30 allowed_pipelines=None, |
31 forbidden_pipelines=None, | |
32 allowed_sources=None, | |
33 rotate_bake_records=True): | |
31 self.appfactory = appfactory | 34 self.appfactory = appfactory |
32 self.app = app | 35 self.app = app |
33 self.out_dir = out_dir | 36 self.out_dir = out_dir |
34 self.force = force | 37 self.force = force |
35 self.allowed_pipelines = allowed_pipelines | 38 self.allowed_pipelines = allowed_pipelines |
36 self.forbidden_pipelines = forbidden_pipelines | 39 self.forbidden_pipelines = forbidden_pipelines |
40 self.allowed_sources = allowed_sources | |
41 self.rotate_bake_records = rotate_bake_records | |
37 | 42 |
38 def bake(self): | 43 def bake(self): |
39 start_time = time.perf_counter() | 44 start_time = time.perf_counter() |
40 logger.debug(" Bake Output: %s" % self.out_dir) | 45 logger.debug(" Bake Output: %s" % self.out_dir) |
41 logger.debug(" Root URL: %s" % self.app.config.get('site/root')) | 46 logger.debug(" Root URL: %s" % self.app.config.get('site/root')) |
87 has_any_pp = False | 92 has_any_pp = False |
88 ppmngr = PipelineManager( | 93 ppmngr = PipelineManager( |
89 self.app, self.out_dir, record_histories) | 94 self.app, self.out_dir, record_histories) |
90 ok_pp = self.allowed_pipelines | 95 ok_pp = self.allowed_pipelines |
91 nok_pp = self.forbidden_pipelines | 96 nok_pp = self.forbidden_pipelines |
97 ok_src = self.allowed_sources | |
92 for source in self.app.sources: | 98 for source in self.app.sources: |
99 if ok_src is not None and source.name not in ok_src: | |
100 continue | |
101 | |
93 pname = get_pipeline_name_for_source(source) | 102 pname = get_pipeline_name_for_source(source) |
94 if ok_pp is not None and pname not in ok_pp: | 103 if ok_pp is not None and pname not in ok_pp: |
95 continue | 104 continue |
96 if nok_pp is not None and pname in nok_pp: | 105 if nok_pp is not None and pname in nok_pp: |
97 continue | 106 continue |
142 | 151 |
143 # Shutdown the pipelines. | 152 # Shutdown the pipelines. |
144 ppmngr.shutdownPipelines() | 153 ppmngr.shutdownPipelines() |
145 | 154 |
146 # Backup previous records. | 155 # Backup previous records. |
147 records_dir, records_fn = os.path.split(records_path) | 156 if self.rotate_bake_records: |
148 records_id, _ = os.path.splitext(records_fn) | 157 records_dir, records_fn = os.path.split(records_path) |
149 for i in range(8, -1, -1): | 158 records_id, _ = os.path.splitext(records_fn) |
150 suffix = '' if i == 0 else '.%d' % i | 159 for i in range(8, -1, -1): |
151 records_path_i = os.path.join( | 160 suffix = '' if i == 0 else '.%d' % i |
152 records_dir, | 161 records_path_i = os.path.join( |
153 '%s%s.records' % (records_id, suffix)) | |
154 if os.path.exists(records_path_i): | |
155 records_path_next = os.path.join( | |
156 records_dir, | 162 records_dir, |
157 '%s.%s.records' % (records_id, i + 1)) | 163 '%s%s.records' % (records_id, suffix)) |
158 if os.path.exists(records_path_next): | 164 if os.path.exists(records_path_i): |
159 os.remove(records_path_next) | 165 records_path_next = os.path.join( |
160 os.rename(records_path_i, records_path_next) | 166 records_dir, |
167 '%s.%s.records' % (records_id, i + 1)) | |
168 if os.path.exists(records_path_next): | |
169 os.remove(records_path_next) | |
170 os.rename(records_path_i, records_path_next) | |
161 | 171 |
162 # Save the bake records. | 172 # Save the bake records. |
163 with format_timed_scope(logger, "saved bake records.", | 173 with format_timed_scope(logger, "saved bake records.", |
164 level=logging.DEBUG, colored=False): | 174 level=logging.DEBUG, colored=False): |
165 current_records.bake_time = time.time() | 175 current_records.bake_time = time.time() |