1 ##########################################################################
2 # Copyright (c) 2009-2011, ETH Zurich.
5 # This file is distributed under the terms in the attached LICENSE file.
6 # If you do not find this file, copies can be found by writing to:
7 # ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8 ##########################################################################
10 import subprocess, os, sys
17 current_level = NORMAL
19 def message(level, message):
20 if level <= current_level:
21 sys.stdout.write(message + '\n')
25 message(QUIET, 'Warning: ' + s)
28 message(QUIET, 'Error: ' + s)
39 def checkcmd(*args, **kwargs):
40 """Run a command as with subprocess.check_call, but either discard or
41 display the output, depending on the current debug level."""
43 # display verbose message saying what we do
44 verbose('executing ' + ' '.join(args[0]))
46 # if non-debug mode, discard stdout
47 # if non-verbose mode, discard stderr as well (hides noise from cmake etc.)
49 if current_level < VERBOSE:
50 devnull = open(os.devnull, 'w')
51 kwargs['stderr'] = devnull
52 if current_level < DEBUG:
53 kwargs['stdout'] = devnull
55 subprocess.check_call(*args, **kwargs)
61 p.add_option('-q', '--quiet', action='store_const', dest=dest, const=QUIET,
62 help='quiet output, only error messages and warnings')
63 p.add_option('-v', '--verbose', action='store_const', dest=dest,
64 const=VERBOSE, help='more verbose output')
65 p.add_option('--debug', action='store_const', dest=dest, const=DEBUG,
66 help='debug output, results of all commands')