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 .save_file (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,18 @@ 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 copy_file (self , path , content ):
135
+ return self .storage .save (path , ContentFile (smart_bytes (content )))
136
+
137
+ def find_source_storage (self , path ):
138
+ for finder in get_finders ():
139
+ for short_path , storage in finder .list ('' ):
140
+ if short_path == path :
141
+ if self .verbose :
142
+ print ("Found storage: %s" % str (self .storage ))
143
+ return storage
144
+ return None
145
+
120
146
def create_packages (self , config ):
121
147
packages = {}
122
148
if not config :
0 commit comments