Commit 96d6d9fd by Kyle MacFarlane Committed by Timothée Peignier

improving windows support

Signed-off-by: Timothée Peignier <timothee.peignier@tryphon.org>
parent e91abcb2
...@@ -2,33 +2,29 @@ import os ...@@ -2,33 +2,29 @@ import os
import tempfile import tempfile
from pipeline.conf import settings from pipeline.conf import settings
from pipeline.compilers import CompilerBase from pipeline.compilers import SubProcessCompiler
class LessCompiler(CompilerBase): class LessCompiler(SubProcessCompiler):
output_extension = 'css' output_extension = 'css'
def match_file(self, filename): def match_file(self, filename):
return filename.endswith('.less') return filename.endswith('.less')
def compile_file(self, content): def compile_file(self, content):
tmp_file = tempfile.NamedTemporaryFile(mode='w+b') in_file, in_filename = tempfile.mkstemp()
tmp_file.write(content) in_file = os.fdopen(in_file, 'w+b')
tmp_file.flush() in_file.write(content)
in_file.flush()
output_file = tempfile.NamedTemporaryFile(mode='w+b')
command = '%s %s %s' % (
command = '%s %s %s %s' % ( settings.PIPELINE_LESS_BINARY,
settings.PIPELINE_LESS_BINARY, tmp_file.name, in_filename,
settings.PIPELINE_LESS_ARGUMENTS, output_file.name settings.PIPELINE_LESS_ARGUMENTS
) )
content = self.execute_command(command, content)
command_output = os.popen(command).read() in_file.close()
os.remove(in_filename)
compiled_content = output_file.read()
output_file.close()
tmp_file.close()
if self.verbose: return content
print command_output
return compiled_content
...@@ -4,6 +4,8 @@ import re ...@@ -4,6 +4,8 @@ import re
import subprocess import subprocess
import urlparse import urlparse
from django.utils.encoding import filepath_to_uri
from pipeline.conf import settings from pipeline.conf import settings
from pipeline.storage import storage from pipeline.storage import storage
from pipeline.utils import to_class from pipeline.utils import to_class
...@@ -128,7 +130,10 @@ class Compressor(object): ...@@ -128,7 +130,10 @@ class Compressor(object):
return "__EMBED__%s" % public_path return "__EMBED__%s" % public_path
if not os.path.isabs(asset_path): if not os.path.isabs(asset_path):
asset_path = self.relative_path(public_path) asset_path = self.relative_path(public_path)
return urlparse.urljoin(settings.PIPELINE_URL, asset_path[1:]) return urlparse.urljoin(
settings.PIPELINE_URL,
filepath_to_uri(asset_path[1:])
)
def embeddable(self, path, variant): def embeddable(self, path, variant):
"""Is the asset embeddable ?""" """Is the asset embeddable ?"""
......
import os import os
import warnings
import tempfile import tempfile
from pipeline.conf import settings from pipeline.conf import settings
from pipeline.compressors import CompressorBase from pipeline.compressors import SubProcessCompressor
warnings.simplefilter('ignore', RuntimeWarning)
class CSSTidyCompressor(SubProcessCompressor):
class CSSTidyCompressor(CompressorBase):
def compress_css(self, css): def compress_css(self, css):
tmp_file = tempfile.NamedTemporaryFile(mode='w+b') out_file, out_filename = tempfile.mkstemp()
tmp_file.write(css) out_file = os.fdopen(out_file, 'rb')
tmp_file.flush()
output_file = tempfile.NamedTemporaryFile(mode='w+b')
command = '%s %s %s %s' % ( command = '%s - %s %s' % (
settings.PIPELINE_CSSTIDY_BINARY, tmp_file.name, settings.PIPELINE_CSSTIDY_BINARY,
settings.PIPELINE_CSSTIDY_ARGUMENTS, output_file.name settings.PIPELINE_CSSTIDY_ARGUMENTS,
out_filename
) )
self.execute_command(command, css)
command_output = os.popen(command).read() filtered_css = out_file.read()
out_file.close()
filtered_css = output_file.read() os.remove(out_filename)
output_file.close()
tmp_file.close()
if self.verbose:
print command_output
return filtered_css return filtered_css
...@@ -33,8 +33,8 @@ PIPELINE_TEMPLATE_NAMESPACE = getattr(settings, 'PIPELINE_TEMPLATE_NAMESPACE', " ...@@ -33,8 +33,8 @@ PIPELINE_TEMPLATE_NAMESPACE = getattr(settings, 'PIPELINE_TEMPLATE_NAMESPACE', "
PIPELINE_TEMPLATE_EXT = getattr(settings, 'PIPELINE_TEMPLATE_EXT', ".jst") PIPELINE_TEMPLATE_EXT = getattr(settings, 'PIPELINE_TEMPLATE_EXT', ".jst")
PIPELINE_TEMPLATE_FUNC = getattr(settings, 'PIPELINE_TEMPLATE_FUNC', "_.template") PIPELINE_TEMPLATE_FUNC = getattr(settings, 'PIPELINE_TEMPLATE_FUNC', "_.template")
PIPELINE_CSSTIDY_BINARY = '/usr/local/bin/csstidy' PIPELINE_CSSTIDY_BINARY = getattr(settings, 'PIPELINE_CSSTIDY_BINARY', '/usr/local/bin/csstidy')
PIPELINE_CSSTIDY_ARGUMENTS = '--template=highest' PIPELINE_CSSTIDY_ARGUMENTS = getattr(settings, 'PIPELINE_CSSTIDY_ARGUMENTS', '--template=highest')
PIPELINE_YUI_BINARY = getattr(settings, 'PIPELINE_YUI_BINARY', '/usr/local/bin/yuicompressor') PIPELINE_YUI_BINARY = getattr(settings, 'PIPELINE_YUI_BINARY', '/usr/local/bin/yuicompressor')
PIPELINE_YUI_CSS_ARGUMENTS = getattr(settings, 'PIPELINE_YUI_CSS_ARGUMENTS', '') PIPELINE_YUI_CSS_ARGUMENTS = getattr(settings, 'PIPELINE_YUI_CSS_ARGUMENTS', '')
...@@ -53,7 +53,7 @@ PIPELINE_SASS_BINARY = getattr(settings, 'PIPELINE_SASS_BINARY', '/usr/local/bin ...@@ -53,7 +53,7 @@ PIPELINE_SASS_BINARY = getattr(settings, 'PIPELINE_SASS_BINARY', '/usr/local/bin
PIPELINE_SASS_ARGUMENTS = getattr(settings, 'PIPELINE_SASS_ARGUMENTS', '') PIPELINE_SASS_ARGUMENTS = getattr(settings, 'PIPELINE_SASS_ARGUMENTS', '')
PIPELINE_LESS_BINARY = getattr(settings, 'PIPELINE_LESS_BINARY', '/usr/local/bin/lessc') PIPELINE_LESS_BINARY = getattr(settings, 'PIPELINE_LESS_BINARY', '/usr/local/bin/lessc')
PIPELINE_LESS_ARGUMENTS = getattr(settings, 'PIPELINE_LESS_ARGUMENTS', '') PIPELINE_LESS_ARGUMENTS = getattr(settings, 'PIPELINE_LESS_ARGUMENTS', '-x')
if PIPELINE_COMPILERS is None: if PIPELINE_COMPILERS is None:
PIPELINE_COMPILERS = [] PIPELINE_COMPILERS = []
...@@ -30,7 +30,7 @@ class CompressedCSSNode(template.Node): ...@@ -30,7 +30,7 @@ class CompressedCSSNode(template.Node):
context = {} context = {}
if not 'template' in package: if not 'template' in package:
package['template'] = "pipeline/css.html" package['template'] = "pipeline/css.html"
if not 'context' in package: if 'context' in package:
context = package['context'] context = package['context']
context.update({ context.update({
'url': self.packager.individual_url(path) 'url': self.packager.individual_url(path)
......
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