LGTM. Thanks, Jose
On Mon, Nov 18, 2013 at 10:34:53AM +0100, Petr Pudlak wrote: > Allow combination of colors, background colors, bold, reverse video, > etc. > > Signed-off-by: Petr Pudlak <[email protected]> > --- > qa/colors.py | 59 > +++++++++++++++++++++++++++++++++++++++++++++------------ > qa/ganeti-qa.py | 2 +- > 2 files changed, 48 insertions(+), 13 deletions(-) > > diff --git a/qa/colors.py b/qa/colors.py > index 77cee42..8edfe7a 100644 > --- a/qa/colors.py > +++ b/qa/colors.py > @@ -24,29 +24,64 @@ > Colors are enabled only if the standard output is a proper terminal. > (Or call check_for_colors() to make a thorough test using "tput".) > > +See http://en.wikipedia.org/wiki/ANSI_escape_code for more possible > additions. > """ > > import os > import subprocess > import sys > > -DEFAULT = '\033[0m' > -RED = '\033[91m' > -GREEN = '\033[92m' > -BLUE = '\033[94m' > -CYAN = '\033[96m' > -WHITE = '\033[97m' > -YELLOW = '\033[93m' > -MAGENTA = '\033[95m' > -GREY = '\033[90m' > -BLACK = '\033[90m' > +DEFAULT = "0" > +BOLD = "1" > +UNDERLINE = "4" > +REVERSE = "7" > + > +BLACK = "30" > +RED = "31" > +GREEN = "32" > +YELLOW = "33" > +BLUE = "34" > +MAGENTA = "35" > +CYAN = "36" > +WHITE = "37" > + > +BG_BLACK = "40" > +BG_RED = "41" > +BG_GREEN = "42" > +BG_YELLOW = "43" > +BG_BLUE = "44" > +BG_MAGENTA = "45" > +BG_CYAN = "46" > +BG_WHITE = "47" > > _enabled = sys.stdout.isatty() > > > +def _escape_one(code): > + return "\033[" + code + "m" if code else "" > + > + > +def _escape(codes): > + if hasattr(codes, "__iter__"): > + return _escape_one(";".join(codes)) > + else: > + return _escape_one(codes) > + > + > +def _reset(): > + return _escape([DEFAULT]) > + > + > def colorize(line, color=None): > - if _enabled and color is not None: > - return color + line + DEFAULT > + """Wraps a given string into ANSI color codes corresponding to given > + color(s). > + > + @param line: a string > + @param color: a color or a list of colors selected from this module's > + constants > + """ > + if _enabled and color: > + return _escape(color) + line + _reset() > else: > return line > > diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py > index 54b821e..3b159f7 100755 > --- a/qa/ganeti-qa.py > +++ b/qa/ganeti-qa.py > @@ -66,7 +66,7 @@ def _FormatHeader(line, end=72, mark="-", color=None): > line = (mark * 4) + " " + line + " " > line += "-" * (end - len(line)) > line = line.rstrip() > - line = colors.colorize(line, color) > + line = colors.colorize(line, color=color) > return line > > > -- > 1.8.4.1 > -- Jose Antonio Lopes Ganeti Engineering Google Germany GmbH Dienerstr. 12, 80331, München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores Steuernummer: 48/725/00206 Umsatzsteueridentifikationsnummer: DE813741370
