Commit f03910d8 by Timothée Peignier

improve syncompress cache busting

parent c454e619
......@@ -8,18 +8,12 @@ class Command(BaseCommand):
make_option('--force',
action='store_true',
default=False,
help='Force update of all files, even if the source files are older than the current compressed file.'
help='Force compression and/or cache busting.'
),
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='Don\'t attempt to compress package.'
)
)
help = 'Updates and compresses CSS and JS on-demand'
......@@ -27,32 +21,30 @@ class Command(BaseCommand):
def handle(self, *args, **options):
from pipeline.packager import Packager
packager = Packager(
force=options.get('force', False),
verbose=int(options.get('verbosity', 1)) >= 2
)
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)
packager = Packager(verbose=verbose)
for package_name in packager.packages['css']:
if args and package_name not in args:
continue
package = packager.package_for('css', package_name)
if packager.verbose or packager.force:
if verbose:
print
message = "CSS Group '%s'" % package_name
print message
print len(message) * '-'
packager.pack_stylesheets(package, sync=sync, bust_cache=bust_cache)
packager.pack_stylesheets(package, sync=sync, force=force)
for package_name in packager.packages['js']:
if args and package_name not in args:
continue
package = packager.package_for('js', package_name)
if packager.verbose or packager.force:
if verbose:
print
message = "JS Group '%s'" % package_name
print message
print len(message) * '-'
packager.pack_javascripts(package, sync=sync, bust_cache=bust_cache)
packager.pack_javascripts(package, sync=sync, force=force)
......@@ -13,8 +13,7 @@ from pipeline.versioning import Versioning
class Packager(object):
def __init__(self, force=False, verbose=False, css_packages=None, js_packages=None):
self.force = force
def __init__(self, verbose=False, css_packages=None, js_packages=None):
self.verbose = verbose
self.compressor = Compressor(verbose)
self.versioning = Versioning(verbose)
......@@ -50,17 +49,17 @@ class Packager(object):
def compile(self, paths):
return self.compiler.compile(paths)
def pack(self, package, compress, signal, sync=False, **kwargs):
if settings.PIPELINE_AUTO or self.force or sync:
def pack(self, package, compress, signal, sync=False, force=False, **kwargs):
if settings.PIPELINE_AUTO or (force and sync):
need_update, version = self.versioning.need_update(
package['output'], package['paths'])
if need_update or self.force:
if need_update or force:
output_filename = self.versioning.output_filename(
package['output'],
version
)
self.versioning.cleanup(package['output'])
if self.verbose or self.force:
if self.verbose:
print "Version: %s" % version
print "Saving: %s" % output_filename
paths = self.compile(package['paths'])
......@@ -69,7 +68,7 @@ class Packager(object):
self.save_file(output_filename, content)
else:
filename_base, filename = os.path.split(package['output'])
version = self.versioning.version_from_file(filename_base, filename)
version = self.versioning.version_from_file(filename_base, filename, force=force)
signal.send(sender=self, package=package, version=version, **kwargs)
return self.versioning.output_filename(package['output'], version)
......
......@@ -12,8 +12,7 @@ js_compressed = Signal(providing_args=["package", "version"])
@receiver(css_compressed)
@receiver(js_compressed)
def invalidate_cache(sender, package, version, bust_cache=False, **kwargs):
def invalidate_cache(sender, package, version, **kwargs):
filename_base, filename = os.path.split(package['output'])
if bust_cache:
cache.set("pipeline:%s" % filename, str(version),
settings.PIPELINE_CACHE_TIMEOUT)
......@@ -19,9 +19,9 @@ class Versioning(object):
def version(self, paths):
return getattr(self.versioner, 'version')(paths)
def version_from_file(self, path, filename):
def version_from_file(self, path, filename, force=False):
version = cache.get("pipeline:%s" % filename)
if not version:
if (not version) or force:
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]+)'))
......
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