Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
more suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaudill committed Sep 14, 2023
1 parent 37b87e1 commit f851ec1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
3 changes: 2 additions & 1 deletion doc/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,8 @@ Most Charliecloud programs accept :code:`-v` to increase logging verbosity and

* :code:`-q` suppresses normal logging.

* :code:`-qq` also suppresses warnings and subprocess stdout.
* :code:`-qq` also suppresses stdout for the program and its subprocesses, and
warnings from the program.

* :code:`-qqq` also suppresses subprocess stderr. (This means subprocesses
are completely silenced no matter what goes wrong!)
Expand Down
23 changes: 8 additions & 15 deletions lib/charliecloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class Log_Level(enum.Enum):
DEBUG = 2
VERBOSE = 1
INFO = 0
QUIET_INFO = -1
QUIET_WARNING = -2
WARNING = -1
STDERR = -2
QUIET_STDERR = -3
# In order to support comparisons between instances of this class, we need to
# define at least one “ordering” operator.
Expand Down Expand Up @@ -469,7 +469,7 @@ def VERBOSE(msg, hint=None, **kwargs):
log(msg, hint, None, "38;5;14m", "", **kwargs) # light cyan (1;36m, not bold)

def WARNING(msg, hint=None, msg_save=True, **kwargs):
if (log_level > Log_Level.QUIET_WARNING):
if (log_level > Log_Level.STDERR):
if (msg_save):
warnings.append(msg)
log(msg, hint, None, "31m", "warning: ", **kwargs) # red
Expand Down Expand Up @@ -515,7 +515,7 @@ def cmd(argv, fail_ok=False, **kwargs):
"""Run command using cmd_base(). If fail_ok, return the exit code whether
or not the process succeeded; otherwise, return (zero) only if the
process succeeded and exit with fatal error if it failed."""
if (log_level < Log_Level.QUIET_INFO):
if (log_level < Log_Level.WARNING):
kwargs["stdout"] = subprocess.DEVNULL
if (log_level <= Log_Level.QUIET_STDERR):
kwargs["stderr"] = subprocess.DEVNULL
Expand Down Expand Up @@ -641,19 +641,12 @@ def init(cli):
global log_festoon, log_fp, log_level, trace_fatal, save_xattrs
save_xattrs = (not cli.no_xattrs)
trace_fatal = (cli.debug or bool(os.environ.get("CH_IMAGE_DEBUG", False)))
if (cli.quiet):
fail_ct = 0
if (trace_fatal):
ERROR("“quiet” incompatible with “debug” and “CH_IMAGE_DEBUG”")
fail_ct += 1
if (cli.verbose):
ERROR("“--quiet” incompatible with “--verbose”")
fail_ct += 1
if (fail_ct != 0):
FATAL(("%d incompatible option" % fail_ct) + ((fail_ct > 1) * "s"))
if ((cli.quiet) and (cli.verbose)):
ERROR("“--quiet” incompatible with “--verbose”")
FATAL("incompatible option")
log_level = Log_Level(cli.verbose - cli.quiet)
assert (-3 <= log_level.value <= 3)
if (log_level <= Log_Level.QUIET_WARNING):
if (log_level <= Log_Level.STDERR):
# suppress writing to stdout (particularly “print”).
sys.stdout = open(os.devnull, 'w')
if ("CH_LOG_FESTOON" in os.environ):
Expand Down
2 changes: 2 additions & 0 deletions test/build/50_ch-image.bats
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ EOF
echo "$output"
[[ $status -eq 0 ]]
[[ $output != *"Dependencies resolved."* ]]
[[ $output != *"this is stdout"* ]]
[[ $output = *"this is stderr"* ]]
[[ $output != *"grown in 4 instructions: tmpimg"* ]]

# quiet level 3
Expand Down

0 comments on commit f851ec1

Please sign in to comment.