changeset 736:13ec290bfc13

bake: Fix some crashes with new blog archive/taxonomy for incremental bakes.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 01 Jun 2016 22:46:11 -0700
parents 6c500fd3194f
children 8b3dfd91cbf6
files piecrust/generation/blogarchives.py piecrust/generation/taxonomy.py
diffstat 2 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/piecrust/generation/blogarchives.py	Wed Jun 01 22:24:35 2016 -0700
+++ b/piecrust/generation/blogarchives.py	Wed Jun 01 22:46:11 2016 -0700
@@ -3,7 +3,7 @@
 from piecrust.chefutil import format_timed_scope
 from piecrust.data.filters import PaginationFilter, IFilterClause
 from piecrust.data.iterators import PageIterator
-from piecrust.generation.base import PageGenerator
+from piecrust.generation.base import PageGenerator, InvalidRecordExtraKey
 
 
 logger = logging.getLogger(__name__)
@@ -63,7 +63,7 @@
         all_years = set()
         dirty_years = set()
         for _, cur_entry in ctx.getAllPageRecords():
-            if cur_entry.source_name == self.source_name:
+            if cur_entry and cur_entry.source_name == self.source_name:
                 dt = datetime.datetime.fromtimestamp(cur_entry.timestamp)
                 all_years.add(dt.year)
                 if cur_entry.was_any_sub_baked:
@@ -90,17 +90,20 @@
         # Create bake entries for the years that were *not* dirty.
         # Otherwise, when checking for deleted pages, we would not find any
         # outputs and would delete those files.
+        all_str_years = [str(y) for y in all_years]
         for prev_entry, cur_entry in ctx.getAllPageRecords():
             if prev_entry and not cur_entry:
                 try:
                     y = ctx.getSeedFromRecordExtraKey(prev_entry.extra_key)
                 except InvalidRecordExtraKey:
                     continue
-                if y in all_years:
-                    logger.debug("Creating unbaked entry for %d archive." % y)
+                if y in all_str_years:
+                    logger.debug(
+                            "Creating unbaked entry for year %s archive." % y)
                     ctx.collapseRecord(prev_entry)
                 else:
-                    logger.debug("No page references year %d anymore." % y)
+                    logger.debug(
+                            "No page references year %s anymore." % y)
 
 
 class IsFromYearFilterClause(IFilterClause):
--- a/piecrust/generation/taxonomy.py	Wed Jun 01 22:24:35 2016 -0700
+++ b/piecrust/generation/taxonomy.py	Wed Jun 01 22:46:11 2016 -0700
@@ -141,9 +141,11 @@
 
         start_time = time.perf_counter()
         page_count = self._bakeTaxonomyTerms(ctx, all_terms, dirty_terms)
-        logger.info(format_timed(
-            start_time,
-            "baked %d %s pages." % (page_count, self.taxonomy.term_name)))
+        if page_count > 0:
+            logger.info(format_timed(
+                start_time,
+                "baked %d %s pages for %s." % (
+                    page_count, self.taxonomy.term_name, self.source_name)))
 
     def _buildDirtyTaxonomyTerms(self, ctx):
         # Build the list of terms for our taxonomy, and figure out which ones
@@ -154,6 +156,9 @@
 
         # Re-bake all taxonomy terms that include new or changed pages.
         for prev_entry, cur_entry in ctx.getBakedPageRecords():
+            if cur_entry.source_name != self.source_name:
+                continue
+
             entries = [cur_entry]
             if prev_entry:
                 entries.append(prev_entry)