Commit 51196b2a by andreas.pelme
parent 7833e1ce
...@@ -7,8 +7,8 @@ COMPRESS_VERSION = getattr(settings, 'COMPRESS_VERSION', False) ...@@ -7,8 +7,8 @@ COMPRESS_VERSION = getattr(settings, 'COMPRESS_VERSION', False)
COMPRESS_VERSION_PLACEHOLDER = getattr(settings, 'COMPRESS_VERSION_PLACEHOLDER', '?') COMPRESS_VERSION_PLACEHOLDER = getattr(settings, 'COMPRESS_VERSION_PLACEHOLDER', '?')
COMPRESS_VERSION_DEFAULT = getattr(settings, 'COMPRESS_VERSION_DEFAULT', '0') COMPRESS_VERSION_DEFAULT = getattr(settings, 'COMPRESS_VERSION_DEFAULT', '0')
COMPRESS_CSS_FILTERS = getattr(settings, 'COMPRESS_CSS_FILTERS', ('compress.filters.csstidy.CSSTidyFilter', )) COMPRESS_CSS_FILTERS = getattr(settings, 'COMPRESS_CSS_FILTERS', ['compress.filters.csstidy.CSSTidyFilter'])
COMPRESS_JS_FILTERS = getattr(settings, 'COMPRESS_JS_FILTERS', ('compress.filters.jsmin.JSMinFilter',)) COMPRESS_JS_FILTERS = getattr(settings, 'COMPRESS_JS_FILTERS', ['compress.filters.jsmin.JSMinFilter'])
COMPRESS_CSS = getattr(settings, 'COMPRESS_CSS', {}) COMPRESS_CSS = getattr(settings, 'COMPRESS_CSS', {})
COMPRESS_JS = getattr(settings, 'COMPRESS_JS', {}) COMPRESS_JS = getattr(settings, 'COMPRESS_JS', {})
......
...@@ -22,12 +22,12 @@ def get_filter(compressor_class): ...@@ -22,12 +22,12 @@ def get_filter(compressor_class):
pass pass
return compressor_class return compressor_class
# since this function is not part of any offical API,
# it is duplicated here to avoid regressions with future/different versions
# of django
def get_mod_func(callback): def get_mod_func(callback):
# Converts 'django.views.news.stories.story_detail' to """
# ['django.views.news.stories', 'story_detail'] Converts 'django.views.news.stories.story_detail' to
('django.views.news.stories', 'story_detail')
"""
try: try:
dot = callback.rindex('.') dot = callback.rindex('.')
except ValueError: except ValueError:
...@@ -51,6 +51,9 @@ def needs_update(output_file, source_files): ...@@ -51,6 +51,9 @@ def needs_update(output_file, source_files):
return (os.stat(compressed_file_full).st_mtime < mtime), mtime return (os.stat(compressed_file_full).st_mtime < mtime), mtime
def media_root(filename): def media_root(filename):
"""
Return the full path to ``filename``. ``filename`` is a relative path name in MEDIA_ROOT
"""
return os.path.join(django_settings.MEDIA_ROOT, filename) return os.path.join(django_settings.MEDIA_ROOT, filename)
def media_url(url): def media_url(url):
...@@ -62,13 +65,13 @@ def write_tmpfile(content): ...@@ -62,13 +65,13 @@ def write_tmpfile(content):
except RuntimeWarning: except RuntimeWarning:
pass pass
fd = open(filename, 'w+') fd = open(filename, 'wb+')
fd.write(content) fd.write(content)
fd.close() fd.close()
return filename return filename
def read_tmpfile(filename, delete=True): def read_tmpfile(filename, delete=True):
fd = open(filename, 'r') fd = open(filename, 'rb')
r = fd.read() r = fd.read()
fd.close() fd.close()
...@@ -78,10 +81,13 @@ def read_tmpfile(filename, delete=True): ...@@ -78,10 +81,13 @@ def read_tmpfile(filename, delete=True):
return r return r
def concat(filenames, separator=''): def concat(filenames, separator=''):
"""
Concatenate the files from the list of the ``filenames``, ouput separated with ``separator``.
"""
r = '' r = ''
for filename in filenames: for filename in filenames:
fd = open(media_root(filename), 'r') fd = open(media_root(filename), 'rb')
r += fd.read() r += fd.read()
r += separator r += separator
fd.close() fd.close()
...@@ -92,7 +98,7 @@ def max_mtime(files): ...@@ -92,7 +98,7 @@ def max_mtime(files):
return int(max([os.stat(media_root(f)).st_mtime for f in files])) return int(max([os.stat(media_root(f)).st_mtime for f in files]))
def save_file(filename, contents): def save_file(filename, contents):
fd = open(media_root(filename), 'w+') fd = open(media_root(filename), 'wb+')
fd.write(contents) fd.write(contents)
fd.close() fd.close()
...@@ -106,12 +112,10 @@ def get_version(mtime): ...@@ -106,12 +112,10 @@ def get_version(mtime):
return str(int(mtime)) return str(int(mtime))
def remove_files(path, filename, verbosity=0): def remove_files(path, filename, verbosity=0):
escaped_filename = settings.COMPRESS_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.COMPRESS_VERSION_PLACEHOLDER)]) regex = re.compile(r'^%s$' % (os.path.basename(get_output_filename(settings.COMPRESS_VERSION_PLACEHOLDER.join([re.escape(part) for part in filename.split(settings.COMPRESS_VERSION_PLACEHOLDER)]), r'\d+'))))
regex = r'^%s$' % (os.path.basename(get_output_filename(escaped_filename, r'\d+')))
for f in os.listdir(path): for f in os.listdir(path):
if re.match(regex, f): if regex.match(f):
if verbosity >= 1: if verbosity >= 1:
print "Removing outdated file %s" % f print "Removing outdated file %s" % f
......
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