Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync compiled file with non-FileSystemStorage (cloud storage) #663

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion pipeline/compilers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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)))

Expand Down
2 changes: 2 additions & 0 deletions tests/tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down