diff piecrust/data/assetor.py @ 871:504ddb370df8

refactor: Fixing some issues with baking assets.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 13 Jun 2017 22:30:27 -0700
parents 48d25fd68b8d
children dcdec4b951a1
line wrap: on
line diff
--- a/piecrust/data/assetor.py	Mon Jun 12 22:30:06 2017 -0700
+++ b/piecrust/data/assetor.py	Tue Jun 13 22:30:27 2017 -0700
@@ -1,9 +1,7 @@
 import os
 import os.path
-import shutil
 import logging
 import collections.abc
-from piecrust import ASSET_DIR_SUFFIX
 from piecrust.sources.base import REL_ASSETS
 from piecrust.uriutil import multi_replace
 
@@ -47,6 +45,10 @@
         self._cacheAssets()
         return len(self._cache_list)
 
+    def _getAssetItems(self):
+        self._cacheAssets()
+        return map(lambda i: i.content_item, self._cache_map.values())
+
     def _debugRenderAssetNames(self):
         self._cacheAssets()
         return list(self._cache_map.keys())
@@ -89,9 +91,9 @@
                     (name, content_item.spec))
 
             # TODO: this assumes a file-system source!
-            uri_build_tokens['%path%'] = (
-                os.path.relpath(a.spec, root_dir).replace('\\', '/'))
-            uri_build_tokens['%filename%'] = a.metadata['filename'],
+            uri_build_tokens['%path%'] = \
+                os.path.relpath(a.spec, root_dir).replace('\\', '/')
+            uri_build_tokens['%filename%'] = a.metadata['filename']
             uri = multi_replace(asset_url_format, uri_build_tokens)
 
             self._cache_map[name] = _AssetInfo(a, uri)
@@ -102,13 +104,3 @@
         if cur_ctx is not None:
             cur_ctx.current_pass_info.used_assets = True
 
-    def copyAssets(self, dest_dir):
-        page_pathname, _ = os.path.splitext(self._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)
-