diff piecrust/baking/records.py @ 334:b034f6f15e22

bake: Several bug taxonomy-related fixes for incorrect incremental bakes. * Improve how the baker processes taxonomy terms and figures out what needs to be re-baked or not. * Create bake entries for clean taxnomy terms so they're not deleted by an incremental bake. * Add more information to bake records. * Slugify taxonomy terms is now done by the route in one place. * Fix a bug where the cache key for invalidating rendered segments was not computed the same way as when the caching was done. * Fix how term combinations are passed around, rendered, printed, parsed, etc. (TODO: more word needed in the routing functions) * Expose to the template whether a taxonomy term is a combination or not. * Display term combinations better in the built-in theme. * Rename `route.taxonomy` to `route.taxonomy_name` to prevent confusion. * Add options to show bake records for previous bakes.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 03 Apr 2015 10:59:50 -0700
parents 1f4c3dae1fe8
children 938be93215cb
line wrap: on
line diff
--- a/piecrust/baking/records.py	Fri Apr 03 08:44:21 2015 -0700
+++ b/piecrust/baking/records.py	Fri Apr 03 10:59:50 2015 -0700
@@ -1,17 +1,16 @@
 import os.path
 import logging
-from piecrust.sources.base import PageSource
 from piecrust.records import Record, TransitionalRecord
 
 
 logger = logging.getLogger(__name__)
 
 
-def _get_transition_key(source_name, rel_path, taxonomy_name=None,
-        taxonomy_term=None):
+def _get_transition_key(source_name, rel_path, taxonomy_info=None):
     key = '%s:%s' % (source_name, rel_path)
-    if taxonomy_name and taxonomy_term:
-        key += ';%s:' % taxonomy_name
+    if taxonomy_info:
+        taxonomy_name, taxonomy_term, taxonomy_source_name = taxonomy_info
+        key += ';%s:%s=' % (taxonomy_source_name, taxonomy_name)
         if isinstance(taxonomy_term, tuple):
             key += '/'.join(taxonomy_term)
         else:
@@ -20,7 +19,7 @@
 
 
 class BakeRecord(Record):
-    RECORD_VERSION = 9
+    RECORD_VERSION = 11
 
     def __init__(self):
         super(BakeRecord, self).__init__()
@@ -32,24 +31,35 @@
 FLAG_NONE = 0
 FLAG_SOURCE_MODIFIED = 2**0
 FLAG_OVERRIDEN = 2**1
+FLAG_FORCED_BY_SOURCE = 2**2
 
 
 class BakeRecordPageEntry(object):
-    def __init__(self, factory, taxonomy_name=None, taxonomy_term=None):
-        self.path = factory.path
-        self.rel_path = factory.rel_path
-        self.source_name = factory.source.name
-        self.taxonomy_name = taxonomy_name
-        self.taxonomy_term = taxonomy_term
-        self.path_mtime = os.path.getmtime(factory.path)
+    """ An entry in the bake record.
+
+        The `taxonomy_info` attribute should be a tuple of the form:
+        (taxonomy name, term, source name)
+    """
+    def __init__(self, source_name, rel_path, path, taxonomy_info=None):
+        self.source_name = source_name
+        self.rel_path = rel_path
+        self.path = path
+        self.taxonomy_info = taxonomy_info
 
         self.flags = FLAG_NONE
         self.config = None
         self.errors = []
         self.out_uris = []
         self.out_paths = []
+        self.clean_uris = []
+        self.clean_out_paths = []
         self.used_source_names = set()
         self.used_taxonomy_terms = set()
+        self.used_pagination_item_count = 0
+
+    @property
+    def path_mtime(self):
+        return os.path.getmtime(self.path)
 
     @property
     def was_baked(self):
@@ -63,11 +73,6 @@
     def num_subs(self):
         return len(self.out_paths)
 
-    def __getstate__(self):
-        state = self.__dict__.copy()
-        del state['path_mtime']
-        return state
-
 
 class TransitionalBakeRecord(TransitionalRecord):
     def __init__(self, previous_path=None):
@@ -82,7 +87,7 @@
 
     def getTransitionKey(self, entry):
         return _get_transition_key(entry.source_name, entry.rel_path,
-                                   entry.taxonomy_name, entry.taxonomy_term)
+                                   entry.taxonomy_info)
 
     def getOverrideEntry(self, factory, uri):
         for pair in self.transitions.values():
@@ -100,10 +105,8 @@
                 return prev
         return None
 
-    def getPreviousEntry(self, source_name, rel_path, taxonomy_name=None,
-            taxonomy_term=None):
-        key = _get_transition_key(source_name, rel_path,
-                taxonomy_name, taxonomy_term)
+    def getPreviousEntry(self, source_name, rel_path, taxonomy_info=None):
+        key = _get_transition_key(source_name, rel_path, taxonomy_info)
         pair = self.transitions.get(key)
         if pair is not None:
             return pair[0]