11from __future__ import unicode_literals
22
33from django .contrib .staticfiles .storage import staticfiles_storage
4- from django .contrib .staticfiles .finders import find
4+ from django .contrib .staticfiles .finders import get_finders , find
55from django .core .files .base import ContentFile
66from django .utils .encoding import smart_bytes
77
@@ -96,7 +96,21 @@ def pack_stylesheets(self, package, **kwargs):
9696 variant = package .variant , ** kwargs )
9797
9898 def compile (self , paths , force = False ):
99- return self .compiler .compile (paths , force = force )
99+ paths = self .compiler .compile (paths , force = force )
100+ for path in paths :
101+ if not self .storage .exists (path ):
102+ if self .verbose :
103+ print ("Compiled file '%s' cannot be found with packager's storage. Locating it." % path )
104+
105+ source_storage = self .find_source_storage (path )
106+ if source_storage is not None :
107+ with source_storage .open (path ) as source_file :
108+ if self .verbose :
109+ print ("Saving: %s" % path )
110+ self .storage .save (path , source_file )
111+ else :
112+ raise IOError ("File does not exist: %s" % path )
113+ return paths
100114
101115 def pack (self , package , compress , signal , ** kwargs ):
102116 output_filename = package .output_filename
@@ -117,6 +131,15 @@ def pack_templates(self, package):
117131 def save_file (self , path , content ):
118132 return self .storage .save (path , ContentFile (smart_bytes (content )))
119133
134+ def find_source_storage (self , path ):
135+ for finder in get_finders ():
136+ for short_path , storage in finder .list ('' ):
137+ if short_path == path :
138+ if self .verbose :
139+ print ("Found storage: %s" % str (self .storage ))
140+ return storage
141+ return None
142+
120143 def create_packages (self , config ):
121144 packages = {}
122145 if not config :
0 commit comments