From b3f282435e429618c3b46c206ec0bfb9d00ebe5f Mon Sep 17 00:00:00 2001 From: Oleg Sharov Date: Sat, 9 Jun 2018 14:45:05 +0400 Subject: [PATCH 1/2] sync compiled file with non-FileSystemStorage (cloud storage) --- pipeline/compilers/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pipeline/compilers/__init__.py b/pipeline/compilers/__init__.py index eb43157e..7e6a2a5f 100644 --- a/pipeline/compilers/__init__.py +++ b/pipeline/compilers/__init__.py @@ -8,6 +8,7 @@ from django.contrib.staticfiles import finders from django.contrib.staticfiles.storage import staticfiles_storage from django.core.files.base import ContentFile +from django.core.files.storage import FileSystemStorage from django.utils.encoding import smart_bytes from django.utils.six import string_types, text_type @@ -41,8 +42,10 @@ def _compile(input_path): compiler.compile_file(infile, outfile, outdated=outdated, force=force, **compiler_options) + output_path = compiler.output_path(input_path, compiler.output_extension) + compiler.sync_file(output_path, outfile) - return compiler.output_path(input_path, compiler.output_extension) + return output_path else: return input_path @@ -67,6 +70,14 @@ def match_file(self, filename): def compile_file(self, infile, outfile, outdated=False, force=False): raise NotImplementedError + def sync_file(self, path, filename): + if isinstance(self.storage, FileSystemStorage): + return + + with open(filename) as f: + print("Syncing '%s'" % filename) + self.save_file(path, f.read()) + def save_file(self, path, content): return self.storage.save(path, ContentFile(smart_bytes(content))) From 2cbdb72b4f0d171ada17039b8f49c1d2091888ee Mon Sep 17 00:00:00 2001 From: Oleg Sharov Date: Thu, 21 Jun 2018 15:08:26 +0400 Subject: [PATCH 2/2] add sync_file() to DummyCompiler --- tests/tests/test_compiler.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tests/test_compiler.py b/tests/tests/test_compiler.py index 5da06371..fd15490e 100644 --- a/tests/tests/test_compiler.py +++ b/tests/tests/test_compiler.py @@ -90,6 +90,8 @@ def match_file(self, path): def compile_file(self, infile, outfile, outdated=False, force=False): return + def sync_file(self, path, filename): + return @pipeline_settings(COMPILERS=['tests.tests.test_compiler.DummyCompiler']) class DummyCompilerTest(TestCase):