Commit 9b2ae111 by Timothée Peignier

pass storage as argument

parent 0122689a
...@@ -10,7 +10,8 @@ from pipeline.utils import to_class ...@@ -10,7 +10,8 @@ from pipeline.utils import to_class
class Compiler(object): class Compiler(object):
def __init__(self, verbose=False): def __init__(self, storage=default_storage, verbose=False):
self.storage = storage
self.verbose = verbose self.verbose = verbose
def compilers(self): def compilers(self):
...@@ -25,10 +26,10 @@ class Compiler(object): ...@@ -25,10 +26,10 @@ class Compiler(object):
new_path = self.output_path(path, compiler.output_extension) new_path = self.output_path(path, compiler.output_extension)
content = self.read_file(path) content = self.read_file(path)
try: try:
compiled_content = compiler.compile_file(content, default_storage.path(path)) compiled_content = compiler.compile_file(content, self.storage.path(path))
self.save_file(new_path, compiled_content) self.save_file(new_path, compiled_content)
except CompilerError: except CompilerError:
if not default_storage.exists(new_path) or not settings.PIPELINE: if not self.storage.exists(new_path) or not settings.PIPELINE:
raise raise
paths[index] = new_path paths[index] = new_path
return paths return paths
...@@ -38,13 +39,13 @@ class Compiler(object): ...@@ -38,13 +39,13 @@ class Compiler(object):
return '.'.join((path[0], extension)) return '.'.join((path[0], extension))
def read_file(self, path): def read_file(self, path):
file = default_storage.open(path, 'rb') file = self.storage.open(path, 'rb')
content = file.read() content = file.read()
file.close() file.close()
return content return content
def save_file(self, path, content): def save_file(self, path, content):
return default_storage.save(path, ContentFile(smart_str(content))) return self.storage.save(path, ContentFile(smart_str(content)))
class CompilerBase(object): class CompilerBase(object):
...@@ -57,9 +58,6 @@ class CompilerBase(object): ...@@ -57,9 +58,6 @@ class CompilerBase(object):
def compile_file(self, content, path): def compile_file(self, content, path):
raise NotImplementedError raise NotImplementedError
def save_file(self, path, content):
return default_storage.save(path, ContentFile(smart_str(content)))
class CompilerError(Exception): class CompilerError(Exception):
pass pass
......
...@@ -6,8 +6,8 @@ import subprocess ...@@ -6,8 +6,8 @@ import subprocess
from itertools import takewhile from itertools import takewhile
from pipeline.conf import settings from pipeline.conf import settings
from pipeline.storage import default_storage
from pipeline.utils import to_class, relpath from pipeline.utils import to_class, relpath
from pipeline.storage import default_storage
MAX_IMAGE_SIZE = 32700 MAX_IMAGE_SIZE = 32700
...@@ -40,7 +40,8 @@ FONT_EXTS = ['.ttf', '.otf', '.woff'] ...@@ -40,7 +40,8 @@ FONT_EXTS = ['.ttf', '.otf', '.woff']
class Compressor(object): class Compressor(object):
asset_contents = {} asset_contents = {}
def __init__(self, verbose=False): def __init__(self, storage=default_storage, verbose=False):
self.storage = storage
self.verbose = verbose self.verbose = verbose
def js_compressor(self): def js_compressor(self):
...@@ -159,7 +160,7 @@ class Compressor(object): ...@@ -159,7 +160,7 @@ class Compressor(object):
font = ext in FONT_EXTS font = ext in FONT_EXTS
if not variant: if not variant:
return False return False
if not (re.search(EMBEDDABLE, path) and default_storage.exists(path)): if not (re.search(EMBEDDABLE, path) and self.storage.exists(path)):
return False return False
if not ext in EMBED_EXTS: if not ext in EMBED_EXTS:
return False return False
......
...@@ -61,10 +61,11 @@ class Package(object): ...@@ -61,10 +61,11 @@ class Package(object):
class Packager(object): class Packager(object):
def __init__(self, verbose=False, css_packages=None, js_packages=None): def __init__(self, storage=default_storage, verbose=False, css_packages=None, js_packages=None):
self.storage = storage
self.verbose = verbose self.verbose = verbose
self.compressor = Compressor(verbose) self.compressor = Compressor(storage=storage, verbose=verbose)
self.compiler = Compiler(verbose) self.compiler = Compiler(storage=storage, verbose=verbose)
if css_packages is None: if css_packages is None:
css_packages = settings.PIPELINE_CSS css_packages = settings.PIPELINE_CSS
if js_packages is None: if js_packages is None:
...@@ -85,7 +86,7 @@ class Packager(object): ...@@ -85,7 +86,7 @@ class Packager(object):
) )
def individual_url(self, filename): def individual_url(self, filename):
return default_storage.url(filename) return self.storage.url(filename)
def pack_stylesheets(self, package, **kwargs): def pack_stylesheets(self, package, **kwargs):
return self.pack(package, self.compressor.compress_css, css_compressed, return self.pack(package, self.compressor.compress_css, css_compressed,
...@@ -113,7 +114,7 @@ class Packager(object): ...@@ -113,7 +114,7 @@ class Packager(object):
return self.compressor.compile_templates(package.templates) return self.compressor.compile_templates(package.templates)
def save_file(self, path, content): def save_file(self, path, content):
return default_storage.save(path, ContentFile(smart_str(content))) return self.storage.save(path, ContentFile(smart_str(content)))
def create_packages(self, config): def create_packages(self, config):
packages = {} packages = {}
......
...@@ -25,7 +25,7 @@ class PipelineStorage(StaticFilesStorage): ...@@ -25,7 +25,7 @@ class PipelineStorage(StaticFilesStorage):
if dry_run: if dry_run:
return [] return []
packager = Packager() packager = Packager(storage=self)
for package_name in packager.packages['css']: for package_name in packager.packages['css']:
package = packager.package_for('css', package_name) package = packager.package_for('css', package_name)
output_file = packager.pack_stylesheets(package) output_file = packager.pack_stylesheets(package)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment