From: Karl Hasselström Date: Wed, 29 Aug 2007 12:22:27 +0000 (+0200) Subject: Write warnings and errors to stderr if not on a terminal X-Git-Tag: v0.14~106 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/8ea5a4e2f42e2ab2c92c2f75e90ee5f552b48364 Write warnings and errors to stderr if not on a terminal Otherwise, they are suppressed along with the rest of the output. But if stdout is a terminal, so that output is not suppressed, write errors through the same Output object as info messages to get the indentation etc. right. Signed-off-by: Karl Hasselström --- diff --git a/stgit/out.py b/stgit/out.py index f80daf2..3464175 100644 --- a/stgit/out.py +++ b/stgit/out.py @@ -64,26 +64,33 @@ class MessagePrinter(object): self.new_line() self.write(string) self.at_start_of_line = string.endswith('\n') + self.__stderr = Output(sys.stderr.write, sys.stderr.flush) self.__stdout = Output(sys.stdout.write, sys.stdout.flush) if sys.stdout.isatty(): self.__out = self.__stdout + self.__err = self.__stdout else: self.__out = Output(lambda msg: None, lambda: None) + self.__err = self.__stderr def stdout(self, line): """Write a line to stdout.""" self.__stdout.write_line(line) def stdout_raw(self, string): """Write a string possibly containing newlines to stdout.""" self.__stdout.write_raw(string) + def err_raw(self, string): + """Write a string possibly containing newlines to the error + output.""" + self.__err.write_raw(string) def info(self, *msgs): for msg in msgs: self.__out.single_line(msg) def note(self, *msgs): self.__out.tagged_lines('Notice', msgs) def warn(self, *msgs): - self.__out.tagged_lines('Warning', msgs) + self.__err.tagged_lines('Warning', msgs) def error(self, *msgs): - self.__out.tagged_lines('Error', msgs) + self.__err.tagged_lines('Error', msgs) def start(self, msg): """Start a long-running operation.""" self.__out.single_line('%s ... ' % msg, print_newline = False)