From b6740cf1d1fe847ae0064f7d7a5be1b24dcf4779 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 19 Jun 2014 08:47:06 -0700 Subject: Make debug and verbose output work properly. --- bin/spack | 4 +++- lib/spack/llnl/util/tty/__init__.py | 22 ++++++++++++++++------ lib/spack/spack/util/executable.py | 16 +++++++++++++++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/bin/spack b/bin/spack index fef793a6ce..df517c1f1d 100755 --- a/bin/spack +++ b/bin/spack @@ -77,8 +77,10 @@ for cmd in spack.cmd.commands: args = parser.parse_args() # Set up environment based on args. -spack.verbose = args.verbose +tty.set_verbose(args.verbose) +tty.set_debug(args.debug) spack.debug = args.debug + spack.spack_working_dir = working_dir if args.mock: from spack.packages import PackageDB diff --git a/lib/spack/llnl/util/tty/__init__.py b/lib/spack/llnl/util/tty/__init__.py index fcbafa82a7..3f413cd46e 100644 --- a/lib/spack/llnl/util/tty/__init__.py +++ b/lib/spack/llnl/util/tty/__init__.py @@ -29,10 +29,20 @@ from StringIO import StringIO from llnl.util.tty.color import * -debug = False -verbose = False +_debug = False +_verbose = False indent = " " +def set_debug(flag): + global _debug + _debug = flag + + +def set_verbose(flag): + global _verbose + _verbose = flag + + def msg(message, *args): cprint("@*b{==>} %s" % cescape(message)) for arg in args: @@ -50,13 +60,13 @@ def info(message, *args, **kwargs): def verbose(message, *args): - if verbose: + if _verbose: info(message, *args, format='c') -def debug(*args): - if debug: - info("Debug: " + message, *args, format='*g') +def debug(message, *args): + if _debug: + info(message, *args, format='g') def error(message, *args): diff --git a/lib/spack/spack/util/executable.py b/lib/spack/spack/util/executable.py index d65f7ed922..2b1b24b728 100644 --- a/lib/spack/spack/util/executable.py +++ b/lib/spack/spack/util/executable.py @@ -38,6 +38,7 @@ class Executable(object): self.exe = name.split(' ') self.returncode = None + def add_default_arg(self, arg): self.exe.append(arg) @@ -61,7 +62,7 @@ class Executable(object): "Consider removing them") cmd = self.exe + list(args) - tty.verbose(" ".join(cmd)) + tty.debug(" ".join(cmd)) try: proc = subprocess.Popen( @@ -80,6 +81,19 @@ class Executable(object): except subprocess.CalledProcessError, e: if fail_on_error: raise + + def __eq__(self, other): + return self.exe == other.exe + + + def __neq__(self, other): + return not (self == other) + + + def __hash__(self): + return hash((type(self),) + tuple(self.exe)) + + def __repr__(self): return "" % self.exe -- cgit v1.2.3-60-g2f50