1
1
from __future__ import unicode_literals
2
2
3
3
from 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
5
5
from django .core .files .base import ContentFile
6
6
from django .utils .encoding import smart_bytes
7
7
@@ -96,7 +96,21 @@ def pack_stylesheets(self, package, **kwargs):
96
96
variant = package .variant , ** kwargs )
97
97
98
98
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
100
114
101
115
def pack (self , package , compress , signal , ** kwargs ):
102
116
output_filename = package .output_filename
@@ -117,6 +131,15 @@ def pack_templates(self, package):
117
131
def save_file (self , path , content ):
118
132
return self .storage .save (path , ContentFile (smart_bytes (content )))
119
133
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
+
120
143
def create_packages (self , config ):
121
144
packages = {}
122
145
if not config :
0 commit comments