Commit 375fd23c authored by Dionysis Grigoropoulos's avatar Dionysis Grigoropoulos Committed by Christos Stavrakakis
Browse files

autopkg: Add option to disable colored output

* Add an option to disable colored output. The default value is auto,
which will determine if output is a tty and act accordingly. This can be
overridden by setting --color=yes to force color output, or --color=no
to disable it completely.
* Update copyright date

closes grnet/devflow#2
parent 97707030
# Copyright 2012, 2013 GRNET S.A. All rights reserved. # Copyright 2012-2014 GRNET S.A. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or # Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following # without modification, are permitted provided that the following
...@@ -44,25 +44,6 @@ from devflow import versioning ...@@ -44,25 +44,6 @@ from devflow import versioning
from devflow import utils from devflow import utils
from devflow import BRANCH_TYPES from devflow import BRANCH_TYPES
if sys.stdout.isatty():
try:
import colors
use_colors = True
except AttributeError:
use_colors = False
else:
use_colors = False
if use_colors:
red = colors.red
green = colors.green
else:
red = lambda x: x
green = lambda x: x
print_red = lambda x: sys.stdout.write(red(x) + "\n")
print_green = lambda x: sys.stdout.write(green(x) + "\n")
AVAILABLE_MODES = ["release", "snapshot"] AVAILABLE_MODES = ["release", "snapshot"]
...@@ -150,9 +131,38 @@ def main(): ...@@ -150,9 +131,38 @@ def main():
default=False, default=False,
action="store_true", action="store_true",
help="Automatically push branches and tags to repo.") help="Automatically push branches and tags to repo.")
parser.add_option("--color",
dest="color_output",
default="auto",
help="Enable/disable colored output. Default mode is" +
" auto, available options are yes/no")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if options.color_output == "yes":
use_colors = True
elif options.color_output == "no":
use_colors = False
else:
if sys.stdout.isatty():
use_colors = True
else:
use_colors = False
red = lambda x: x
green = lambda x: x
if use_colors:
try:
import colors
red = colors.red
green = colors.green
except AttributeError:
pass
print_red = lambda x: sys.stdout.write(red(x) + "\n")
print_green = lambda x: sys.stdout.write(green(x) + "\n")
if options.help: if options.help:
print_help(parser.get_prog_name()) print_help(parser.get_prog_name())
parser.print_help() parser.print_help()
......
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