From ce07794a617912f212f234839d1f4b36b1db98e2 Mon Sep 17 00:00:00 2001 From: Sebastien Luttringer <sebastien.luttringer@smartjog.com> Date: Tue, 18 Oct 2011 19:18:38 +0200 Subject: [PATCH] add --no-color option to is This allow displaying to be done without coloration --- bin/is | 6 ++++++ installsystems/printer.py | 12 +++++++----- samples/installsystems.conf | 3 +++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/bin/is b/bin/is index 684d580..c7ca3b5 100755 --- a/bin/is +++ b/bin/is @@ -14,6 +14,7 @@ import re import fnmatch import warnings import installsystems +import installsystems.printer import installsystems.tools as istools import installsystems.argparse as argparse # to be removed when python2.7 from installsystems.printer import * @@ -318,6 +319,8 @@ p_main.add_argument("-C", "--cache", default=None, help="path of the repository cache") p_main.add_argument("--no-cache", action="store_true", default=False, help="not use persistent db caching") +p_main.add_argument("--no-color", action="store_true", default=False, + help="dot not display colored output") p_main.add_argument("-t", "--timeout", dest="timeout", type=int, default=3, help="download timeout (default 3)") @@ -499,6 +502,9 @@ try: # no warning if we are not in debug mode if not installsystems.debug: warnings.filterwarnings("ignore") + # disable coloring if asked + if args.no_color: + installsystems.printer.NOCOLOR = True # except for install command we parse all args! if args.func is not c_install: args = p_main.parse_args(namespace=args) diff --git a/installsystems/printer.py b/installsystems/printer.py index 4aec988..0b7eceb 100644 --- a/installsystems/printer.py +++ b/installsystems/printer.py @@ -10,7 +10,9 @@ import sys import os import installsystems -color = { +NOCOLOR = False + +COLOR = { # regular "black": "\033[30m", "B": "\033[30m", @@ -46,11 +48,11 @@ def out(message="", fd=sys.stdout, endl=os.linesep, flush=True): Print message colorised in fd ended by endl ''' # color subsitution - for c in color: - if fd.isatty(): - message = message.replace("#%s#" % c, color[c]) - else: + for c in COLOR: + if not fd.isatty() or NOCOLOR: message = message.replace("#%s#" % c, "") + else: + message = message.replace("#%s#" % c, COLOR[c]) # convert unicode into str before write # this can cause issue on python 2.6 if type(message) == unicode: diff --git a/samples/installsystems.conf b/samples/installsystems.conf index 0210cd9..4808d26 100644 --- a/samples/installsystems.conf +++ b/samples/installsystems.conf @@ -14,6 +14,9 @@ # disable cache of remote repository #no_cache = 1 +# disable output coloring +#no_color = 1 + # disable check of script during build #no_check = 1 -- GitLab