diff piecrust/data/assetor.py @ 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 22c6f6a3d0a0
children 18978cf6d1ac
line wrap: on
line diff
--- 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)