Commit 9e349fb9 authored by Dionysis Grigoropoulos's avatar Dionysis Grigoropoulos Committed by Christos Stavrakakis
Browse files

snf-deploy: Add option (--disable-colors) to disable color printing in terminal

parent 51929d49
...@@ -22,6 +22,7 @@ def setup_env(confdir="conf", packages="packages", ...@@ -22,6 +22,7 @@ def setup_env(confdir="conf", packages="packages",
print(" * Using %s and %s for packages and templates accordingly..." % (packages, templates)) print(" * Using %s and %s for packages and templates accordingly..." % (packages, templates))
autoconf = ast.literal_eval(autoconf) autoconf = ast.literal_eval(autoconf)
disable_colors = ast.literal_eval(disable_colors)
conf = Conf.configure(confdir=confdir, cluster_name=cluster_name, autoconf=autoconf) conf = Conf.configure(confdir=confdir, cluster_name=cluster_name, autoconf=autoconf)
env.env = Env(conf) env.env = Env(conf)
...@@ -30,6 +31,9 @@ def setup_env(confdir="conf", packages="packages", ...@@ -30,6 +31,9 @@ def setup_env(confdir="conf", packages="packages",
env.user = env.env.user env.user = env.env.user
env.shell = "/bin/bash -c" env.shell = "/bin/bash -c"
if disable_colors:
disable_color()
if env.env.cms.hostname in [env.env.accounts.hostname, env.env.cyclades.hostname, env.env.pithos.hostname]: if env.env.cms.hostname in [env.env.accounts.hostname, env.env.cyclades.hostname, env.env.pithos.hostname]:
env.cms_pass = True env.cms_pass = True
else: else:
......
...@@ -254,8 +254,10 @@ def fabcommand(args, env, actions, nodes=[]): ...@@ -254,8 +254,10 @@ def fabcommand(args, env, actions, nodes=[]):
fabcmd = "fab " fabcmd = "fab "
fabcmd += " --fabfile {4}/fabfile.py \ fabcmd += " --fabfile {4}/fabfile.py \
setup_env:confdir={0},packages={1},templates={2},cluster_name={3},autoconf={5} \ setup_env:confdir={0},packages={1},templates={2},cluster_name={3},\
".format(args.confdir, env.packages, env.templates, args.cluster_name, env.lib, args.autoconf) autoconf={5}, disable_colors={6} \
".format(args.confdir, env.packages, env.templates, args.cluster_name,
env.lib, args.autoconf, args.disable_colors)
if nodes: if nodes:
hosts = [env.nodes_info[n].hostname for n in nodes] hosts = [env.nodes_info[n].hostname for n in nodes]
...@@ -400,8 +402,13 @@ def parse_options(): ...@@ -400,8 +402,13 @@ def parse_options():
parser.add_argument("actions", type=str, nargs="*", parser.add_argument("actions", type=str, nargs="*",
help="Run one or more of the supported subcommands") help="Run one or more of the supported subcommands")
# disable colors in terminal
parser.add_argument("--disable-colors", dest="disable_colors", default=False,
action="store_true", help="Disable colors in terminal")
return parser.parse_args() return parser.parse_args()
def get_actions(*args): def get_actions(*args):
actions = { actions = {
# prepare actions # prepare actions
......
...@@ -16,6 +16,25 @@ import tempfile ...@@ -16,6 +16,25 @@ import tempfile
from snfdeploy import massedit from snfdeploy import massedit
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def disable_color():
HEADER = ''
OKBLUE = ''
OKGREEN = ''
WARNING = ''
FAIL = ''
ENDC = ''
if not sys.stdout.isatty():
disable_color()
class Host(object): class Host(object):
def __init__(self, hostname, ip, mac, domain): def __init__(self, hostname, ip, mac, domain):
...@@ -164,27 +183,10 @@ class Conf(object): ...@@ -164,27 +183,10 @@ class Conf(object):
self.nodes.set("info", "public_iface", get_default_route()[1]) self.nodes.set("info", "public_iface", get_default_route()[1])
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def disable(self):
self.HEADER = ''
self.OKBLUE = ''
self.OKGREEN = ''
self.WARNING = ''
self.FAIL = ''
self.ENDC = ''
def debug(host, msg): def debug(host, msg):
print bcolors.HEADER + host + \ print HEADER + host + \
bcolors.OKBLUE + ": " + msg + bcolors.ENDC OKBLUE + ": " + msg + ENDC
def check_pidfile(pidfile): def check_pidfile(pidfile):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment