From 6b3ead8c4a7476365a8486098d80545576a0da09 Mon Sep 17 00:00:00 2001 From: kennyballou Date: Wed, 20 Mar 2013 15:06:23 -0600 Subject: Suppress pdflatex build output, unless verbose --- xnt/__init__.py | 2 ++ xnt/build/tex.py | 11 ++++++++--- xnt/xenant.py | 5 +++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/xnt/__init__.py b/xnt/__init__.py index 71c7358..e78fbc2 100644 --- a/xnt/__init__.py +++ b/xnt/__init__.py @@ -41,6 +41,8 @@ __license__ = """ along with this program. If not, see . """ +VERBOSE = False + from xnt.tasks import cp, mv, mkdir, rm, create_zip, log, xntcall, call, setup def target(target_fn): diff --git a/xnt/build/tex.py b/xnt/build/tex.py index 91a5edd..15bb6fb 100644 --- a/xnt/build/tex.py +++ b/xnt/build/tex.py @@ -20,6 +20,7 @@ import os import logging import xnt.tasks +from xnt import VERBOSE LOGGER = logging.getLogger(__name__) @@ -28,6 +29,7 @@ def pdflatex(document, bibtex=False, makeglossary=False): """Generate PDF LaTeX Document""" + devnull = None if VERBOSE else open(os.devnull, 'w') documentbase = os.path.splitext(document)[0] cwd = os.getcwd() os.chdir(path) @@ -36,15 +38,16 @@ def pdflatex(document, cmd = ["pdflatex", document, "-halt-on-error",] if draftmode: cmd.append('-draftmode') - return xnt.tasks.call(cmd) + return xnt.tasks.call(cmd, stdout=devnull) def run_bibtex(): """Generate BibTex References""" - return xnt.tasks.call(["bibtex", documentbase + ".aux"]) + return xnt.tasks.call(["bibtex", documentbase + ".aux"], + stdout=devnull) def makeglossaries(): """Generate Glossary""" - return xnt.tasks.call(["makeglossaries", documentbase]) + return xnt.tasks.call(["makeglossaries", documentbase], stdout=devnull) error_codes = [] error_codes.append(pdf(draftmode=True)) @@ -55,6 +58,8 @@ def pdflatex(document, error_codes.append(pdf(draftmode=True)) error_codes.append(pdf(draftmode=False)) os.chdir(cwd) + if devnull: + devnull.close() return sum(error_codes) def clean(path="./", remove_pdf=False): diff --git a/xnt/xenant.py b/xnt/xenant.py index f084e83..3dc4a70 100644 --- a/xnt/xenant.py +++ b/xnt/xenant.py @@ -22,7 +22,7 @@ import sys import time import logging import argparse -from xnt import __version__ +import xnt from xnt.status_codes import SUCCESS, ERROR, UNKNOWN_ERROR logging.basicConfig(format="%(message)s") @@ -36,6 +36,7 @@ def main(): args = parse_args(sys.argv[1:]) build_file = "./build.py" if args["verbose"]: + xnt.VERBOSE = True LOGGER.setLevel(logging.INFO) logging.getLogger("xnt.tasks").setLevel(logging.INFO) if args["build-file"]: @@ -155,7 +156,7 @@ def parse_args(args_in): parser.add_argument( "--version", action="version", - version=__version__, + version=xnt.__version__, help="print the version information and quit") parser.add_argument( "-b", "--build-file", -- cgit v1.2.1