Make debug and verbose output work properly.

This commit is contained in:
Todd Gamblin 2014-06-19 08:47:06 -07:00
parent 4608b674e5
commit b6740cf1d1
3 changed files with 34 additions and 8 deletions

View file

@ -77,8 +77,10 @@ for cmd in spack.cmd.commands:
args = parser.parse_args() args = parser.parse_args()
# Set up environment based on 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.debug = args.debug
spack.spack_working_dir = working_dir spack.spack_working_dir = working_dir
if args.mock: if args.mock:
from spack.packages import PackageDB from spack.packages import PackageDB

View file

@ -29,10 +29,20 @@
from llnl.util.tty.color import * from llnl.util.tty.color import *
debug = False _debug = False
verbose = False _verbose = False
indent = " " indent = " "
def set_debug(flag):
global _debug
_debug = flag
def set_verbose(flag):
global _verbose
_verbose = flag
def msg(message, *args): def msg(message, *args):
cprint("@*b{==>} %s" % cescape(message)) cprint("@*b{==>} %s" % cescape(message))
for arg in args: for arg in args:
@ -50,13 +60,13 @@ def info(message, *args, **kwargs):
def verbose(message, *args): def verbose(message, *args):
if verbose: if _verbose:
info(message, *args, format='c') info(message, *args, format='c')
def debug(*args): def debug(message, *args):
if debug: if _debug:
info("Debug: " + message, *args, format='*g') info(message, *args, format='g')
def error(message, *args): def error(message, *args):

View file

@ -38,6 +38,7 @@ def __init__(self, name):
self.exe = name.split(' ') self.exe = name.split(' ')
self.returncode = None self.returncode = None
def add_default_arg(self, arg): def add_default_arg(self, arg):
self.exe.append(arg) self.exe.append(arg)
@ -61,7 +62,7 @@ def __call__(self, *args, **kwargs):
"Consider removing them") "Consider removing them")
cmd = self.exe + list(args) cmd = self.exe + list(args)
tty.verbose(" ".join(cmd)) tty.debug(" ".join(cmd))
try: try:
proc = subprocess.Popen( proc = subprocess.Popen(
@ -80,6 +81,19 @@ def __call__(self, *args, **kwargs):
except subprocess.CalledProcessError, e: except subprocess.CalledProcessError, e:
if fail_on_error: raise 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): def __repr__(self):
return "<exe: %s>" % self.exe return "<exe: %s>" % self.exe