Mercurial > piecrust2
comparison piecrust/baking/baker.py @ 105:7d2fdf43d7ca
Property clean all caches when force baking, except the `app` cache.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 17 Sep 2014 21:49:25 -0700 |
parents | 0445a2232de7 |
children | 133845647083 |
comparison
equal
deleted
inserted
replaced
104:28518b515513 | 105:7d2fdf43d7ca |
---|---|
18 from piecrust.sources.base import (PageFactory, | 18 from piecrust.sources.base import (PageFactory, |
19 REALM_NAMES, REALM_USER, REALM_THEME) | 19 REALM_NAMES, REALM_USER, REALM_THEME) |
20 | 20 |
21 | 21 |
22 logger = logging.getLogger(__name__) | 22 logger = logging.getLogger(__name__) |
23 | |
24 | |
25 class BakingError(Exception): | |
26 pass | |
23 | 27 |
24 | 28 |
25 class PageBaker(object): | 29 class PageBaker(object): |
26 def __init__(self, app, out_dir, force=False, record=None, | 30 def __init__(self, app, out_dir, force=False, record=None, |
27 copy_assets=True): | 31 copy_assets=True): |
112 | 116 |
113 override = self.record.getOverrideEntry(factory, uri) | 117 override = self.record.getOverrideEntry(factory, uri) |
114 if override is not None: | 118 if override is not None: |
115 override_source = self.app.getSource(override.source_name) | 119 override_source = self.app.getSource(override.source_name) |
116 if override_source.realm == factory.source.realm: | 120 if override_source.realm == factory.source.realm: |
117 raise Exception( | 121 raise BakingError( |
118 "Page '%s' maps to URL '%s' but is overriden by page" | 122 "Page '%s' maps to URL '%s' but is overriden by page" |
119 "'%s:%s'." % (factory.ref_spec, uri, | 123 "'%s:%s'." % (factory.ref_spec, uri, |
120 override.source_name, override.rel_path)) | 124 override.source_name, override.rel_path)) |
121 logger.debug("'%s' [%s] is overriden by '%s:%s'. Skipping" % | 125 logger.debug("'%s' [%s] is overriden by '%s:%s'. Skipping" % |
122 (factory.ref_spec, uri, override.source_name, | 126 (factory.ref_spec, uri, override.source_name, |
203 ctx, rp = self._bakeSingle(page, sub_uri, cur_sub, out_path, | 207 ctx, rp = self._bakeSingle(page, sub_uri, cur_sub, out_path, |
204 pagination_filter, custom_data) | 208 pagination_filter, custom_data) |
205 except Exception as ex: | 209 except Exception as ex: |
206 if self.app.debug: | 210 if self.app.debug: |
207 logger.exception(ex) | 211 logger.exception(ex) |
208 raise Exception("Error baking page '%s' for URL '%s'." % | 212 raise BakingError("Error baking page '%s' for URL '%s'." % |
209 (page.ref_spec, uri)) from ex | 213 (page.ref_spec, uri)) from ex |
210 | 214 |
211 # Copy page assets. | 215 # Copy page assets. |
212 if (cur_sub == 1 and self.copy_assets and | 216 if (cur_sub == 1 and self.copy_assets and |
213 ctx.used_assets is not None): | 217 ctx.used_assets is not None): |
371 if max_time >= record.previous.bake_time: | 375 if max_time >= record.previous.bake_time: |
372 reason = "templates modified" | 376 reason = "templates modified" |
373 | 377 |
374 if reason is not None: | 378 if reason is not None: |
375 # We have to bake everything from scratch. | 379 # We have to bake everything from scratch. |
376 cache_dir = self.app.cache.getCacheDir('baker') | 380 for cache_name in self.app.cache.getCacheNames( |
377 if os.path.isdir(cache_dir): | 381 except_names=['app']): |
378 logger.debug("Cleaning baker cache: %s" % cache_dir) | 382 cache_dir = self.app.cache.getCacheDir(cache_name) |
379 shutil.rmtree(cache_dir) | 383 if os.path.isdir(cache_dir): |
384 logger.debug("Cleaning baker cache: %s" % cache_dir) | |
385 shutil.rmtree(cache_dir) | |
380 self.force = True | 386 self.force = True |
381 record.incremental_count = 0 | 387 record.incremental_count = 0 |
382 record.clearPrevious() | 388 record.clearPrevious() |
383 logger.info(format_timed(start_time, | 389 logger.info(format_timed(start_time, |
384 "cleaned cache (reason: %s)" % reason)) | 390 "cleaned cache (reason: %s)" % reason)) |
537 for e in excs: | 543 for e in excs: |
538 logger.exception(e) | 544 logger.exception(e) |
539 else: | 545 else: |
540 for e in excs: | 546 for e in excs: |
541 log_friendly_exception(logger, e) | 547 log_friendly_exception(logger, e) |
542 raise Exception("Baking was aborted due to errors.") | 548 raise BakingError("Baking was aborted due to errors.") |
543 | 549 |
544 | 550 |
545 class BakeScheduler(object): | 551 class BakeScheduler(object): |
546 _EMPTY = object() | 552 _EMPTY = object() |
547 _WAIT = object() | 553 _WAIT = object() |