Commit 2f4bc57f by Timothée Peignier

avoid using broken os.path.commonprefix

parent d0a012d9
......@@ -10,6 +10,7 @@ docs/_build/
*.egg-info
.coverage
coverage/
tests/static/
tests/assets/js/dummy.js
.tox/
.DS_Store
\ No newline at end of file
......@@ -3,6 +3,8 @@ import os
import re
import subprocess
from itertools import takewhile
from pipeline.conf import settings
from pipeline.storage import storage
from pipeline.utils import to_class, relpath
......@@ -80,7 +82,7 @@ class Compressor(object):
if not paths:
return compiled
namespace = settings.PIPELINE_TEMPLATE_NAMESPACE
base_path = os.path.commonprefix(paths)
base_path = self.base_path(paths)
for path in paths:
contents = self.read_file(path)
contents = re.sub(r"\r?\n", "", contents)
......@@ -97,6 +99,12 @@ class Compressor(object):
compiled
])
def base_path(self, paths):
def names_equal(name):
return all(n==name[0] for n in name[1:])
directory_levels = zip(*[p.split(os.sep) for p in paths])
return os.sep.join(x[0] for x in takewhile(names_equal, directory_levels))
def template_name(self, path, base):
"""Find out the name of a JS template"""
if not base:
......
......@@ -50,6 +50,12 @@ class CompressorTest(TestCase):
relative_path = self.compressor.relative_path('/var/www/static/images/sprite.png')
self.assertEquals(relative_path, '/images/sprite.png')
def test_base_path(self):
base_path = self.compressor.base_path([
'js/templates/form.jst', 'js/templates/field.jst'
])
self.assertEquals(base_path, 'js/templates')
def test_absolute_path(self):
absolute_path = self.compressor.absolute_path('../../images/sprite.png',
'css/plugins/')
......
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