Commit 29eee6f8 by Timothée Peignier

allow to bust version cache without compressing files

parent c5dbf437
......@@ -49,7 +49,7 @@ class Compressor(object):
return to_class(settings.PIPELINE_CSS_COMPRESSOR)
css_compressor = property(css_compressor)
def compress_js(self, paths, templates=None, asset_url=None):
def compress_js(self, paths, templates=None, asset_url=None, **kwargs):
"""Concatenate and compress JS files"""
js = self.concatenate(paths)
if templates:
......@@ -58,7 +58,7 @@ class Compressor(object):
js = getattr(self.js_compressor(verbose=self.verbose), 'compress_js')(js)
return js
def compress_css(self, paths, variant=None, asset_url=None):
def compress_css(self, paths, variant=None, asset_url=None, **kwargs):
"""Concatenate and compress CSS files"""
css = self.concatenate_and_rewrite(paths, variant)
css = getattr(self.css_compressor(verbose=self.verbose), 'compress_css')(css)
......
......@@ -10,18 +10,31 @@ class Command(BaseCommand):
default=False,
help='Force update of all files, even if the source files are older than the current compressed file.'
),
make_option('--dry-run',
action='store_false',
default=True,
help='Don\'t attempt to update files.'
),
make_option('--no-cache-bust',
dest='bust_cache',
action='store_false',
default=True,
help='Don\'t update version cache.'
)
)
help = 'Updates and compresses CSS and JS on-demand, without restarting Django'
help = 'Updates and compresses CSS and JS on-demand'
args = '<group>'
def handle(self, group=None, **options):
from pipeline.packager import Packager
packager = Packager(
sync=True,
force=options.get('force', False),
verbose=int(options.get('verbosity', 1)) >= 2
)
sync = options.get('dry_run', True),
bust_cache = options.get('bust_cache', True)
for package_name in packager.packages['css']:
if group and package_name != group:
continue
......@@ -31,7 +44,7 @@ class Command(BaseCommand):
message = "CSS Group '%s'" % package_name
print message
print len(message) * '-'
packager.pack_stylesheets(package)
packager.pack_stylesheets(package, sync=sync, bust_cache=bust_cache)
for package_name in packager.packages['js']:
if group and package_name != group:
......@@ -42,4 +55,4 @@ class Command(BaseCommand):
message = "JS Group '%s'" % package_name
print message
print len(message) * '-'
packager.pack_javascripts(package)
packager.pack_javascripts(package, sync=sync, bust_cache=bust_cache)
......@@ -13,10 +13,9 @@ from pipeline.versioning import Versioning
class Packager(object):
def __init__(self, force=False, sync=False, verbose=False, css_packages=None, js_packages=None):
def __init__(self, force=False, verbose=False, css_packages=None, js_packages=None):
self.force = force
self.verbose = verbose
self.sync = sync
self.compressor = Compressor(verbose)
self.versioning = Versioning(verbose)
self.compiler = Compiler(verbose)
......@@ -43,16 +42,16 @@ class Packager(object):
return urlparse.urljoin(settings.PIPELINE_URL,
self.compressor.relative_path(filename)[1:])
def pack_stylesheets(self, package):
def pack_stylesheets(self, package, **kwargs):
variant = package.get('variant', None)
return self.pack(package, self.compressor.compress_css, css_compressed,
variant=variant)
variant=variant, **kwargs)
def compile(self, paths):
return self.compiler.compile(paths)
def pack(self, package, compress, signal, **kwargs):
if settings.PIPELINE_AUTO or self.force or self.sync:
def pack(self, package, compress, signal, sync=False, **kwargs):
if settings.PIPELINE_AUTO or self.force or sync:
need_update, version = self.versioning.need_update(
package['output'], package['paths'])
if need_update or self.force:
......@@ -68,14 +67,14 @@ class Packager(object):
content = compress(paths,
asset_url=self.individual_url(output_filename), **kwargs)
self.save_file(output_filename, content)
signal.send(sender=self, package=package, version=version)
else:
filename_base, filename = os.path.split(package['output'])
version = self.versioning.version_from_file(filename_base, filename)
signal.send(sender=self, package=package, version=version, **kwargs)
return self.versioning.output_filename(package['output'], version)
def pack_javascripts(self, package):
return self.pack(package, self.compressor.compress_js, js_compressed, templates=package['templates'])
def pack_javascripts(self, package, **kwargs):
return self.pack(package, self.compressor.compress_js, js_compressed, templates=package['templates'], **kwargs)
def pack_templates(self, package):
return self.compressor.compile_templates(package['templates'])
......
......@@ -12,7 +12,9 @@ js_compressed = Signal(providing_args=["package", "version"])
@receiver(css_compressed)
@receiver(js_compressed)
def invalidate_cache(sender, package, version, **kwargs):
def invalidate_cache(sender, package, version, bust_cache=False, **kwargs):
filename_base, filename = os.path.split(package['output'])
if bust_cache:
print "bust_cache"
cache.set("pipeline:%s" % filename, str(version),
settings.PIPELINE_CACHE_TIMEOUT)
......@@ -25,7 +25,7 @@ class Versioning(object):
filename = settings.PIPELINE_VERSION_PLACEHOLDER.join([re.escape(part)
for part in filename.split(settings.PIPELINE_VERSION_PLACEHOLDER)])
regex = re.compile(r'^%s$' % self.output_filename(filename, r'([A-Za-z0-9]+)'))
for f in storage.listdir(path)[1]:
for f in sorted(storage.listdir(path)[1], reverse=True):
match = regex.match(f)
if match and match.groups():
version = match.group(1)
......
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