Skip to content
Snippets Groups Projects
Commit ce07794a authored by Sebastien Luttringer's avatar Sebastien Luttringer
Browse files

add --no-color option to is

This allow displaying to be done without coloration
parent 48d0f32d
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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:
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment