Use Popen.communicate instead of handling std in and out manually.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import subprocess
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
from compressor.conf import settings
|
||||
from compressor.filters import FilterBase, FilterError
|
||||
from compressor.utils import cmd_split
|
||||
|
||||
|
||||
class ClosureCompilerFilter(FilterBase):
|
||||
@@ -12,15 +13,9 @@ class ClosureCompilerFilter(FilterBase):
|
||||
command = '%s %s' % (settings.CLOSURE_COMPILER_BINARY, arguments)
|
||||
|
||||
try:
|
||||
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
p.stdin.write(self.content)
|
||||
p.stdin.close()
|
||||
p = Popen(cmd_split(command), stdout=PIPE, stdin=PIPE, stderr=PIPE)
|
||||
filtered, err = p.communicate(self.content)
|
||||
|
||||
filtered = p.stdout.read()
|
||||
p.stdout.close()
|
||||
|
||||
err = p.stderr.read()
|
||||
p.stderr.close()
|
||||
except IOError, e:
|
||||
raise FilterError(e)
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import subprocess
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
from compressor.conf import settings
|
||||
from compressor.filters import FilterBase, FilterError
|
||||
from compressor.utils import cmd_split
|
||||
|
||||
|
||||
class YUICompressorFilter(FilterBase):
|
||||
@@ -19,16 +20,8 @@ class YUICompressorFilter(FilterBase):
|
||||
command += ' --verbose'
|
||||
|
||||
try:
|
||||
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
p.stdin.write(self.content)
|
||||
p.stdin.close()
|
||||
|
||||
filtered = p.stdout.read()
|
||||
p.stdout.close()
|
||||
|
||||
err = p.stderr.read()
|
||||
p.stderr.close()
|
||||
|
||||
p = Popen(cmd_split(command), stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
||||
filtered, err = p.communicate(self.content)
|
||||
except IOError, e:
|
||||
raise FilterError(e)
|
||||
|
||||
@@ -42,11 +35,13 @@ class YUICompressorFilter(FilterBase):
|
||||
|
||||
return filtered
|
||||
|
||||
|
||||
class YUICSSFilter(YUICompressorFilter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(YUICSSFilter, self).__init__(*args, **kwargs)
|
||||
self.type = 'css'
|
||||
|
||||
|
||||
class YUIJSFilter(YUICompressorFilter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(YUIJSFilter, self).__init__(*args, **kwargs)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import os
|
||||
from shlex import split as cmd_split
|
||||
|
||||
from compressor.cache import cache
|
||||
from compressor.conf import settings
|
||||
from compressor.exceptions import FilterError
|
||||
|
||||
Reference in New Issue
Block a user