Commit 3440388a by Timothée Peignier

use pipe.communicate

parent 0333ad56
...@@ -80,23 +80,11 @@ class SubProcessCompiler(CompilerBase): ...@@ -80,23 +80,11 @@ class SubProcessCompiler(CompilerBase):
pipe = subprocess.Popen(command, shell=True, cwd=cwd, pipe = subprocess.Popen(command, shell=True, cwd=cwd,
stdout=subprocess.PIPE, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
if not content:
if content: return content
pipe.stdin.write(content) stdout, stderr = pipe.communicate(content)
pipe.stdin.close() if stderr:
raise CompilerError(stderr)
compressed_content = pipe.stdout.read()
pipe.stdout.close()
error = pipe.stderr.read()
pipe.stderr.close()
if pipe.wait() != 0:
if not error:
error = "Unable to apply %s compiler" % self.__class__.__name__
raise CompilerError(error)
if self.verbose: if self.verbose:
print(error) print(stderr)
return stdout
return compressed_content
...@@ -229,25 +229,11 @@ class SubProcessCompressor(CompressorBase): ...@@ -229,25 +229,11 @@ class SubProcessCompressor(CompressorBase):
def execute_command(self, command, content): def execute_command(self, command, content):
pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
stdin=subprocess.PIPE, stderr=subprocess.PIPE) stdin=subprocess.PIPE, stderr=subprocess.PIPE)
if not content:
try: return content
pipe.stdin.write(smart_bytes(content)) stdout, stderr = pipe.communicate(smart_bytes(content))
except IOError as e: if stderr:
message = "Unable to pipe content to command: %s" % command raise CompressorError(stderr)
raise CompressorError(message, e)
pipe.stdin.close()
compressed_content = pipe.stdout.read()
pipe.stdout.close()
error = pipe.stderr.read()
pipe.stderr.close()
if pipe.wait() != 0:
if not error:
error = "Unable to apply %s compressor" % self.__class__.__name__
raise CompressorError(error)
if self.verbose: if self.verbose:
print(error) print(stderr)
return compressed_content return stdout
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