changeset 827:570f89414b2c

Assetor is now responsible for copying assets, to allow customization
author Ben Artin <ben@artins.org>
date Sun, 01 Jan 2017 18:22:24 -0500
parents 7f235e65ef5d
children bca06fc064c0
files piecrust/baking/single.py piecrust/data/assetor.py
diffstat 2 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/piecrust/baking/single.py	Sun Jan 01 18:02:13 2017 -0500
+++ b/piecrust/baking/single.py	Sun Jan 01 18:22:24 2017 -0500
@@ -1,6 +1,5 @@
 import os.path
 import queue
-import shutil
 import logging
 import threading
 import urllib.parse
@@ -167,14 +166,7 @@
                 logger.debug("Copying page assets to: %s" % out_assets_dir)
                 _ensure_dir_exists(out_assets_dir)
 
-                page_pathname, _ = os.path.splitext(qualified_page.path)
-                in_assets_dir = page_pathname + ASSET_DIR_SUFFIX
-                for fn in os.listdir(in_assets_dir):
-                    full_fn = os.path.join(in_assets_dir, fn)
-                    if os.path.isfile(full_fn):
-                        dest_ap = os.path.join(out_assets_dir, fn)
-                        logger.debug("  %s -> %s" % (full_fn, dest_ap))
-                        shutil.copy(full_fn, dest_ap)
+                qualified_path.source.buildPageAssetor().copyAssets(page, out_assets_dir)
 
             # Figure out if we have more work.
             has_more_subs = False
--- a/piecrust/data/assetor.py	Sun Jan 01 18:02:13 2017 -0500
+++ b/piecrust/data/assetor.py	Sun Jan 01 18:22:24 2017 -0500
@@ -1,5 +1,6 @@
 import os
 import os.path
+import shutil
 import logging
 from piecrust import ASSET_DIR_SUFFIX
 from piecrust.uriutil import multi_replace
@@ -92,4 +93,13 @@
         cpi = self._page.app.env.exec_info_stack.current_page_info
         if cpi is not None:
             cpi.render_ctx.current_pass_info.used_assets = True
-
+            
+    def copyAssets(self, page, dest_dir):
+        page_pathname, _ = os.path.splitext(page.path)
+        in_assets_dir = page_pathname + ASSET_DIR_SUFFIX
+        for fn in os.listdir(in_assets_dir):
+            full_fn = os.path.join(in_assets_dir, fn)
+            if os.path.isfile(full_fn):
+                dest_ap = os.path.join(dest_dir, fn)
+                logger.debug("  %s -> %s" % (full_fn, dest_ap))
+                shutil.copy(full_fn, dest_ap)