1
1
from django .contrib .staticfiles .storage import staticfiles_storage
2
- from django .contrib .staticfiles .finders import find
2
+ from django .contrib .staticfiles .finders import get_finders , find
3
3
from django .core .files .base import ContentFile
4
4
from django .utils .encoding import smart_bytes
5
5
@@ -98,11 +98,25 @@ def pack_stylesheets(self, package, **kwargs):
98
98
variant = package .variant , ** kwargs )
99
99
100
100
def compile (self , paths , compiler_options = {}, force = False ):
101
- return self .compiler .compile (
101
+ paths = self .compiler .compile (
102
102
paths ,
103
103
compiler_options = compiler_options ,
104
104
force = force ,
105
105
)
106
+ for path in paths :
107
+ if not self .storage .exists (path ):
108
+ if self .verbose :
109
+ print ("Compiled file '%s' cannot be found with packager's storage. Locating it." % path )
110
+
111
+ source_storage = self .find_source_storage (path )
112
+ if source_storage is not None :
113
+ with source_storage .open (path ) as source_file :
114
+ if self .verbose :
115
+ print ("Saving: %s" % path )
116
+ self .storage .save (path , source_file )
117
+ else :
118
+ raise IOError ("File does not exist: %s" % path )
119
+ return paths
106
120
107
121
def pack (self , package , compress , signal , ** kwargs ):
108
122
output_filename = package .output_filename
@@ -127,6 +141,15 @@ def pack_templates(self, package):
127
141
def save_file (self , path , content ):
128
142
return self .storage .save (path , ContentFile (smart_bytes (content )))
129
143
144
+ def find_source_storage (self , path ):
145
+ for finder in get_finders ():
146
+ for short_path , storage in finder .list ('' ):
147
+ if short_path == path :
148
+ if self .verbose :
149
+ print ("Found storage: %s" % str (self .storage ))
150
+ return storage
151
+ return None
152
+
130
153
def create_packages (self , config ):
131
154
packages = {}
132
155
if not config :
0 commit comments