This patch adds support for a new set of configuration options to allow
the user to change the colour presets. The predefined colour presets are
the following:
faded for debugging output
alert for important messages
highlight highlighted text
pass PASS colour
fail FAIL colour
info the INFO label
debug the DEBUG label
warning the WARNING label
error the ERROR label
log_header the date and ip address in each log message
You can override these values on both the controller and the slave by
addint a [colours] section to your conf file and setting different
values for these presets. For example:
[colours]
faded = yellow default false
alert = red default true
Each colour preset comprises of three values:
(foreground colour, background colour, bold flag)
You can use one of the 16 standard colours or (if your terminal supports
it) use the extended palette. The standard colours are:
black, red, green, yellow, blue, magenta, cyan,
light-gray, dark-gray, light-red, light-green,
light-yellow, light-blue, light-magenta, light-cyan,
white
The colours from the extended palette can be accessed by their index
as follows (256 colours are available):
extended(0)
extended(5)
...
extended(255)
The complete palette can be found here:
http://misc.flogisoft.com/bash/tip_colors_and_formatting
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
---
lnst-ctl | 3 +++
lnst/Common/Config.py | 31 +++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/lnst-ctl b/lnst-ctl
index 210c6dc..f4fc31d 100755
--- a/lnst-ctl
+++ b/lnst-ctl
@@ -19,6 +19,7 @@ import re
import datetime
from lnst.Common.Logs import LoggingCtl, log_exc_traceback
from lnst.Common.Config import Config
+from lnst.Common.Colours import load_presets_from_config
from lnst.Controller.NetTestController import NetTestController, NetTestError
from lnst.Controller.NetTestResultSerializer import NetTestResultSerializer
@@ -130,6 +131,8 @@ def main():
elif opt in ("-o", "--disable-pool-checks"):
pool_checks = 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'),
diff --git a/lnst/Common/Config.py b/lnst/Common/Config.py
index 3d65048..6e0deae 100644
--- a/lnst/Common/Config.py
+++ b/lnst/Common/Config.py
@@ -15,6 +15,7 @@ import sys
import logging
import re
from ConfigParser import ConfigParser
+from lnst.Common.Utils import bool_it
from lnst.Common.NetUtils import verify_ip_address, verify_mac_address
DefaultRPCPort = 9999
@@ -73,6 +74,8 @@ class Config():
"action" : self.optionPath,
"name" : "log_dir"}
+ self.colours_scheme()
+
def slave_scheme(self):
self.options['environment'] = dict()
self.options['environment']['log_dir'] = {\
@@ -96,6 +99,21 @@ class Config():
"action" : self.optionTimeval,
"name" : "expiration_period"}
+ self.colours_scheme()
+
+ def colours_scheme(self):
+ self.options['colours'] = dict()
+ for preset in ["default", "faded", "alert",
"highlight",
+ "pass", "fail", "error",
"info", "debug", "warning",
+ "log_header"]:
+ self.options['colours'][preset] = {\
+ "value" : None, "additive" : False,
+ "action" : self.optionColour, "name" : preset}
+
+ self.options['colours']["disable_colours"] = {\
+ "value" : False, "additive" : False,
+ "action" : self.optionBool, "name" :
"disable_colours"}
+
def get_config(self):
return self.options
@@ -226,6 +244,19 @@ class Config():
return timeval
+ def optionColour(self, option, cfg_path):
+ colour = option.split()
+ if len(colour) != 3:
+ msg = "Colour must be specified by 3"\
+ " values (foreground, background, bold)"\
+ " sepparated by whitespace."
+ raise ConfigError(msg)
+
+ return colour
+
+ def optionBool(self, option, cfg_path):
+ return bool_it(option)
+
def dump_config(self):
string = ""
for section in self.options:
--
1.7.7.6