From 0b4bf7b36febedbc9e36e666f688a377a9ad156a Mon Sep 17 00:00:00 2001 From: "Thomas @ BeeDesk" Date: Sun, 27 Sep 2015 16:57:56 -0700 Subject: [PATCH] Improved packager.compile() to handle s3 storage when compiler generates output to the local one. This patch copies the generated file. Conflicts: pipeline/packager.py --- pipeline/packager.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/pipeline/packager.py b/pipeline/packager.py index ee66fa3d..796a1d5f 100644 --- a/pipeline/packager.py +++ b/pipeline/packager.py @@ -1,5 +1,5 @@ from django.contrib.staticfiles.storage import staticfiles_storage -from django.contrib.staticfiles.finders import find +from django.contrib.staticfiles.finders import get_finders, find from django.core.files.base import ContentFile from django.utils.encoding import smart_bytes @@ -98,11 +98,25 @@ def pack_stylesheets(self, package, **kwargs): variant=package.variant, **kwargs) def compile(self, paths, compiler_options={}, force=False): - return self.compiler.compile( + paths = self.compiler.compile( paths, compiler_options=compiler_options, force=force, ) + for path in paths: + if not self.storage.exists(path): + if self.verbose: + print("Compiled file '%s' cannot be found with packager's storage. Locating it." % path) + + source_storage = self.find_source_storage(path) + if source_storage is not None: + with source_storage.open(path) as source_file: + if self.verbose: + print("Saving: %s" % path) + self.storage.save(path, source_file) + else: + raise IOError("File does not exist: %s" % path) + return paths def pack(self, package, compress, signal, **kwargs): output_filename = package.output_filename @@ -127,6 +141,15 @@ def pack_templates(self, package): def save_file(self, path, content): return self.storage.save(path, ContentFile(smart_bytes(content))) + def find_source_storage(self, path): + for finder in get_finders(): + for short_path, storage in finder.list(''): + if short_path == path: + if self.verbose: + print("Found storage: %s" % str(self.storage)) + return storage + return None + def create_packages(self, config): packages = {} if not config: