Mercurial > piecrust2
changeset 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 | 28518b515513 |
children | 5effaf1978d0 |
files | piecrust/baking/baker.py piecrust/cache.py |
diffstat | 2 files changed, 19 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/piecrust/baking/baker.py Mon Sep 15 08:12:55 2014 -0700 +++ b/piecrust/baking/baker.py Wed Sep 17 21:49:25 2014 -0700 @@ -22,6 +22,10 @@ logger = logging.getLogger(__name__) +class BakingError(Exception): + pass + + class PageBaker(object): def __init__(self, app, out_dir, force=False, record=None, copy_assets=True): @@ -114,7 +118,7 @@ if override is not None: override_source = self.app.getSource(override.source_name) if override_source.realm == factory.source.realm: - raise Exception( + raise BakingError( "Page '%s' maps to URL '%s' but is overriden by page" "'%s:%s'." % (factory.ref_spec, uri, override.source_name, override.rel_path)) @@ -205,7 +209,7 @@ except Exception as ex: if self.app.debug: logger.exception(ex) - raise Exception("Error baking page '%s' for URL '%s'." % + raise BakingError("Error baking page '%s' for URL '%s'." % (page.ref_spec, uri)) from ex # Copy page assets. @@ -373,10 +377,12 @@ if reason is not None: # We have to bake everything from scratch. - cache_dir = self.app.cache.getCacheDir('baker') - if os.path.isdir(cache_dir): - logger.debug("Cleaning baker cache: %s" % cache_dir) - shutil.rmtree(cache_dir) + for cache_name in self.app.cache.getCacheNames( + except_names=['app']): + cache_dir = self.app.cache.getCacheDir(cache_name) + if os.path.isdir(cache_dir): + logger.debug("Cleaning baker cache: %s" % cache_dir) + shutil.rmtree(cache_dir) self.force = True record.incremental_count = 0 record.clearPrevious() @@ -539,7 +545,7 @@ else: for e in excs: log_friendly_exception(logger, e) - raise Exception("Baking was aborted due to errors.") + raise BakingError("Baking was aborted due to errors.") class BakeScheduler(object):
--- a/piecrust/cache.py Mon Sep 15 08:12:55 2014 -0700 +++ b/piecrust/cache.py Wed Sep 17 21:49:25 2014 -0700 @@ -35,6 +35,12 @@ def getCacheDir(self, name): return os.path.join(self.base_dir, name) + def getCacheNames(self, except_names=None): + _, dirnames, __ = next(os.walk(self.base_dir)) + if except_names is None: + return dirnames + return [dn for dn in dirnames if dn not in except_names] + class SimpleCache(object): def __init__(self, base_dir):