Mercurial > piecrust2
comparison 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 |
comparison
equal
deleted
inserted
replaced
220:84e2bc2d16cb | 221:f82262f59600 |
---|---|
1 import os | 1 import os |
2 import os.path | 2 import os.path |
3 import sys | |
3 import json | 4 import json |
4 import hashlib | 5 import hashlib |
5 import logging | 6 import logging |
6 import platform | 7 import platform |
7 import subprocess | 8 import subprocess |
8 from piecrust.processing.base import SimpleFileProcessor | 9 from piecrust.processing.base import ( |
10 SimpleFileProcessor, ExternalProcessException) | |
9 from piecrust.processing.tree import FORCE_BUILD | 11 from piecrust.processing.tree import FORCE_BUILD |
10 | 12 |
11 | 13 |
12 logger = logging.getLogger(__name__) | 14 logger = logging.getLogger(__name__) |
13 | 15 |
63 | 65 |
64 # On Windows, we need to run the process in a shell environment | 66 # On Windows, we need to run the process in a shell environment |
65 # otherwise it looks like `PATH` isn't taken into account. | 67 # otherwise it looks like `PATH` isn't taken into account. |
66 shell = (platform.system() == 'Windows') | 68 shell = (platform.system() == 'Windows') |
67 try: | 69 try: |
68 retcode = subprocess.call(args, shell=shell) | 70 proc = subprocess.Popen( |
71 args, shell=shell, | |
72 stderr=subprocess.PIPE) | |
73 stdout_data, stderr_data = proc.communicate() | |
69 except FileNotFoundError as ex: | 74 except FileNotFoundError as ex: |
70 logger.error("Tried running LESS processor with command: %s" % | 75 logger.error("Tried running LESS processor with command: %s" % |
71 args) | 76 args) |
72 raise Exception("Error running LESS processor. " | 77 raise Exception("Error running LESS processor. " |
73 "Did you install it?") from ex | 78 "Did you install it?") from ex |
74 if retcode != 0: | 79 if proc.returncode != 0: |
75 raise Exception("Error occured in LESS compiler. Please check " | 80 raise ExternalProcessException( |
76 "log messages above for more information.") | 81 stderr_data.decode(sys.stderr.encoding)) |
82 | |
77 return True | 83 return True |
78 | 84 |
79 def _ensureInitialized(self): | 85 def _ensureInitialized(self): |
80 if self._conf is not None: | 86 if self._conf is not None: |
81 return | 87 return |