Check if stdout is a tty
[snf-image-creator] / image_creator / main.py
index 30fa7d6..9a5aeab 100644 (file)
@@ -37,7 +37,8 @@ from image_creator import __version__ as version
 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
@@ -159,9 +160,9 @@ def image_creator():
                                                                 "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)
@@ -281,7 +282,10 @@ def main():
         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)