comparison piecrust/baking/baker.py @ 371:c2ca72fb7f0b 2.0.0a8

caching: Use separate caches for config variants and other contexts. * The `_cache` directory is now organized in multiple "sub-caches" for different contexts. * A new context is created when config variants or overrides are applied. * `serve` context uses a different context that the other commends, to prevent the `bake` command's output from messing up the preview server (e.g. with how asset URLs are generated differently between the two). * Fix a few places where the cache directory was referenced directly.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 03 May 2015 23:59:46 -0700
parents 4b1019bb2533
children e7b865f8f335
comparison
equal deleted inserted replaced
370:a1bbe66cba03 371:c2ca72fb7f0b
1 import time 1 import time
2 import os.path 2 import os.path
3 import shutil
4 import hashlib 3 import hashlib
5 import logging 4 import logging
6 import threading 5 import threading
7 from piecrust.baking.records import ( 6 from piecrust.baking.records import (
8 TransitionalBakeRecord, BakeRecordPageEntry) 7 TransitionalBakeRecord, BakeRecordPageEntry)
9 from piecrust.baking.scheduler import BakeScheduler 8 from piecrust.baking.scheduler import BakeScheduler
10 from piecrust.baking.single import (BakingError, PageBaker) 9 from piecrust.baking.single import (BakingError, PageBaker)
11 from piecrust.chefutil import format_timed, log_friendly_exception 10 from piecrust.chefutil import format_timed, log_friendly_exception
12 from piecrust.sources.base import ( 11 from piecrust.sources.base import (
13 PageFactory,
14 REALM_NAMES, REALM_USER, REALM_THEME) 12 REALM_NAMES, REALM_USER, REALM_THEME)
15 13
16 14
17 logger = logging.getLogger(__name__) 15 logger = logging.getLogger(__name__)
18 16
139 if max_time >= record.previous.bake_time: 137 if max_time >= record.previous.bake_time:
140 reason = "templates modified" 138 reason = "templates modified"
141 139
142 if reason is not None: 140 if reason is not None:
143 # We have to bake everything from scratch. 141 # We have to bake everything from scratch.
144 for cache_name in self.app.cache.getCacheNames( 142 self.app.cache.clearCaches(except_names=['app'])
145 except_names=['app']):
146 cache_dir = self.app.cache.getCacheDir(cache_name)
147 if os.path.isdir(cache_dir):
148 logger.debug("Cleaning baker cache: %s" % cache_dir)
149 shutil.rmtree(cache_dir)
150 self.force = True 143 self.force = True
151 record.incremental_count = 0 144 record.incremental_count = 0
152 record.clearPrevious() 145 record.clearPrevious()
153 logger.info(format_timed( 146 logger.info(format_timed(
154 start_time, 147 start_time,