commit 6c2b04cabb541bddeaef1f25f6351aa532e9ef7d
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Fri Jun 28 18:51:44 2013 +0200
lnst-ctl, lnst-slave: Disabling colours
This patch adds a possibility to lnst-ctl and lnst-slave to disable the
output colouring by a CLI options. Either -m or --no-colour can be used.
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst-ctl | 10 +++++++---
lnst-slave | 11 ++++++++---
lnst/Common/Logs.py | 4 ++--
3 files changed, 17 insertions(+), 8 deletions(-)
---
diff --git a/lnst-ctl b/lnst-ctl
index f4fc31d..3e9b62b 100755
--- a/lnst-ctl
+++ b/lnst-ctl
@@ -37,6 +37,7 @@ def usage():
" network communication during\n" \
" the test"
print " -h, --help print this message"
+ print " -m, --no-colours disable coloured terminal output"
print " -o, --disable-pool-checks don't check the availability
of\n"\
" machines in the pool"
print " -c, --cleanup perform config cleanup\n" \
@@ -85,9 +86,9 @@ def main():
try:
opts, args = getopt.getopt(
sys.argv[1:],
- "dhr:cx:po",
+ "dhr:cx:pom",
["debug", "help", "recipe=",
"cleanup", "result=",
- "packet-capture", "disable-pool-checks"]
+ "packet-capture", "disable-pool-checks",
"no-colours"]
)
except getopt.GetoptError as err:
print str(err)
@@ -117,6 +118,7 @@ def main():
result_path = None
packet_capture = False
pool_checks = True
+ coloured_output = not config.get_option("colours",
"disable_colours")
for opt, arg in opts:
if opt in ("-d", "--debug"):
debug += 1
@@ -130,13 +132,15 @@ def main():
packet_capture = True
elif opt in ("-o", "--disable-pool-checks"):
pool_checks = False
+ elif opt in ("-m", "--no-colours"):
+ coloured_output = False
load_presets_from_config(config)
date = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S")
log_ctl = LoggingCtl(debug,
log_dir=config.get_option('environment',
'log_dir'),
- log_subdir=date)
+ log_subdir=date, colours=coloured_output)
action = args.pop()
diff --git a/lnst-slave b/lnst-slave
index 91f257c..996cd32 100755
--- a/lnst-slave
+++ b/lnst-slave
@@ -30,6 +30,7 @@ def usage():
print " -h, --help print this message"
print " -e, --daemonize go to background after init"
print " -i, --pidfile file to write daemonized process pid"
+ print " -m, --no-colours disable coloured terminal output"
print " -p, --port xmlrpc port to listen on"
sys.exit()
@@ -40,8 +41,8 @@ def main():
try:
opts = getopt.getopt(
sys.argv[1:],
- "dhei:p:",
- ["debug", "help", "daemonize",
"pidfile", "port"]
+ "dhei:p:m",
+ ["debug", "help", "daemonize",
"pidfile", "port", "no-colours"]
)[0]
except getopt.GetoptError as err:
print str(err)
@@ -60,6 +61,7 @@ def main():
daemon = False
pidfile = "lnst-slave.pid"
port = None
+ coloured_output = not config.get_option("colours",
"disable_colours")
for opt, arg in opts:
if opt in ("-d", "--debug"):
debug = True
@@ -71,9 +73,12 @@ def main():
pidfile = arg
elif opt in ("-p", "--port"):
port = int(arg)
+ elif opt in ("-m", "--no-colours"):
+ coloured_output = False
log_ctl = LoggingCtl(debug,
- log_dir=config.get_option('environment',
'log_dir'))
+ log_dir=config.get_option('environment',
'log_dir'),
+ colours=coloured_output)
logging.info("Started")
if port:
diff --git a/lnst/Common/Logs.py b/lnst/Common/Logs.py
index 73989f5..33a43a7 100644
--- a/lnst/Common/Logs.py
+++ b/lnst/Common/Logs.py
@@ -94,7 +94,7 @@ class LoggingCtl:
slaves = {}
transmit_handler = None
- def __init__(self, debug=False, log_dir=None, log_subdir=""):
+ def __init__(self, debug=False, log_dir=None, log_subdir="",
colours=True):
if log_dir != None:
self.log_folder = os.path.abspath(os.path.join(log_dir, log_subdir))
else:
@@ -107,7 +107,7 @@ class LoggingCtl:
#the display_handler will display logs in the terminal
self.display_handler = logging.StreamHandler(sys.stdout)
- self.display_handler.setFormatter(MultilineFormatter(coloured=True))
+ self.display_handler.setFormatter(MultilineFormatter(colours))
if not debug:
self.display_handler.setLevel(logging.INFO)
else: