from image_creator import util
from image_creator.disk import Disk
from image_creator.util import get_command, FatalError, MD5
-from image_creator.output import Output, Output_with_progress, Silent, error
+from image_creator.output import Output, Output_wth_progress, Silent, \
+ Silent_wth_colors, error
from image_creator.os_type import get_os_class
from image_creator.kamaki_wrapper import Kamaki
import sys
"must be set")
if options.silent:
- out = Silent()
+ out = Silent_wth_colors() if sys.stdout.isatty() else Silent()
else:
- out = Output_with_progress()
+ out = Output_wth_progress() if sys.stdout.isatty() else Output()
title = 'snf-image-creator %s' % version
out.output(title)
ret = image_creator()
sys.exit(ret)
except FatalError as e:
- error(e)
+ if sys.stdout.isatty():
+ error(e)
+ else:
+ error(e, True, False)
sys.exit(1)
from colors import red, green, yellow
-def error(msg, new_line=True):
+def error(msg, new_line=True, color=True):
nl = "\n" if new_line else ''
- sys.stderr.write(red('Error: %s' % msg) + nl)
+ if color:
+ sys.stderr.write(red('Error: %s' % msg) + nl)
+ else:
+ sys.stderr.write('Error: %s' % msg + nl)
-def warn(msg, new_line=True):
+def warn(msg, new_line=True, color=True):
nl = "\n" if new_line else ''
- sys.stderr.write(yellow("Warning: %s" % msg) + nl)
+ if color:
+ sys.stderr.write(yellow("Warning: %s" % msg) + nl)
+ else:
+ sys.stderr.write("Warning: %s" % msg + nl)
-def success(msg, new_line=True):
+def success(msg, new_line=True, color=True):
nl = "\n" if new_line else ''
- sys.stdout.write(green(msg) + nl)
+ if color:
+ sys.stdout.write(green(msg) + nl)
+ else:
+ sys.stdout.write(msg + nl)
if not nl:
sys.stdout.flush()
class Output(object):
def error(self, msg, new_line=True):
- error(msg, new_line)
+ error(msg, new_line, False)
def warn(self, msg, new_line=True):
- warn(msg, new_line)
+ warn(msg, new_line, False)
def success(self, msg, new_line=True):
- success(msg, new_line)
+ success(msg, new_line, False)
def output(self, msg='', new_line=True):
output(msg, new_line)
return generator
-class Output_with_progress(Output):
+class Output_wth_colors(Output):
+ def error(self, msg, new_line=True):
+ error(msg, new_line)
+
+ def warn(self, msg, new_line=True):
+ warn(msg, new_line)
+
+ def success(self, msg, new_line=True):
+ success(msg, new_line)
+
+
+class Output_wth_progress(Output_wth_colors):
class Progress(Bar):
MESSAGE_LENGTH = 30
}
def __init__(self, title, bar_type='default'):
- super(Output_with_progress.Progress, self).__init__()
+ super(Output_wth_progress.Progress, self).__init__()
self.title = title
self.fill = '#'
self.bar_prefix = ' ['
pass
class Progress(Output.Progress):
- def __init__(self, title, bar_type):
+ def __init__(self, title, bar_type='default'):
pass
def success(self, result):
pass
+class Silent_wth_colors(Silent):
+ def error(self, msg, new_line=True):
+ error(msg, new_line)
+
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :