Browse Source

pdflatex output is now logged line per line (not as a whole text at the end of compilation)

pull/71/head
Louis 10 years ago
parent
commit
5db2eb7c49
  1. 33
      patacrep/build.py

33
patacrep/build.py

@ -4,6 +4,7 @@ import codecs
import copy import copy
import glob import glob
import logging import logging
import threading
import os.path import os.path
from subprocess import Popen, PIPE, call from subprocess import Popen, PIPE, call
@ -127,6 +128,13 @@ class Songbook(object):
renderer.render_tex(output, config) renderer.render_tex(output, config)
def _log_pipe(pipe):
"""Log content from `pipe`."""
while 1:
line = pipe.readline()
if not bool(line):
break
LOGGER.debug(line.strip())
class SongbookBuilder(object): class SongbookBuilder(object):
"""Provide methods to compile a songbook.""" """Provide methods to compile a songbook."""
@ -217,6 +225,7 @@ class SongbookBuilder(object):
stdin=PIPE, stdin=PIPE,
stdout=PIPE, stdout=PIPE,
stderr=PIPE, stderr=PIPE,
universal_newlines=True,
env=os.environ) env=os.environ)
except Exception as error: except Exception as error:
LOGGER.debug(error) LOGGER.debug(error)
@ -224,13 +233,25 @@ class SongbookBuilder(object):
if not self.interactive: if not self.interactive:
process.stdin.close() process.stdin.close()
log = ''
line = process.stdout.readline()
while line:
log += str(line)
line = process.stdout.readline()
LOGGER.debug(log)
standard_output = threading.Thread(
target=_log_pipe,
kwargs={
'pipe' : process.stdout,
}
)
standard_error = threading.Thread(
target=_log_pipe,
kwargs={
'pipe' : process.stderr,
}
)
standard_output.daemon = True
standard_error.daemon = True
standard_error.start()
standard_output.start()
standard_error.join()
standard_output.join()
process.wait() process.wait()
if process.returncode: if process.returncode:

Loading…
Cancel
Save