Mercurial > piecrust2
diff piecrust/processing/less.py @ 221:f82262f59600
bake: Fix processing record bugs and error logging for external processes.
Fix problems with processing records not being collapsed correctly.
Make it possible to capture external processes' `stderr` output.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 03 Feb 2015 08:21:43 -0800 |
parents | b4724e577a8c |
children | c1d4e86a3918 |
line wrap: on
line diff
--- a/piecrust/processing/less.py Tue Feb 03 08:20:30 2015 -0800 +++ b/piecrust/processing/less.py Tue Feb 03 08:21:43 2015 -0800 @@ -1,11 +1,13 @@ import os import os.path +import sys import json import hashlib import logging import platform import subprocess -from piecrust.processing.base import SimpleFileProcessor +from piecrust.processing.base import ( + SimpleFileProcessor, ExternalProcessException) from piecrust.processing.tree import FORCE_BUILD @@ -65,15 +67,19 @@ # otherwise it looks like `PATH` isn't taken into account. shell = (platform.system() == 'Windows') try: - retcode = subprocess.call(args, shell=shell) + proc = subprocess.Popen( + args, shell=shell, + stderr=subprocess.PIPE) + stdout_data, stderr_data = proc.communicate() except FileNotFoundError as ex: logger.error("Tried running LESS processor with command: %s" % args) raise Exception("Error running LESS processor. " "Did you install it?") from ex - if retcode != 0: - raise Exception("Error occured in LESS compiler. Please check " - "log messages above for more information.") + if proc.returncode != 0: + raise ExternalProcessException( + stderr_data.decode(sys.stderr.encoding)) + return True def _ensureInitialized(self):