diff --git a/bin/is b/bin/is index 684d58031bf53b5c5b3c9ab9f7205bcd0d07fa81..c7ca3b529b5f77093fef827cdde7f8b667db4a46 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 4aec988cde5754e8981c6026edd5cee9a0ab3246..0b7eceb79adc98cb0d545b1dbce35c48f989ce09 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 0210cd9df4232b778ecd8dfe0d92f82acea5eaca..4808d260c892d92265fb4d56b09d82a277bde7ef 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