Add Output module for dialog-based output
[snf-image-creator] / image_creator / main.py
index 9a5aeab..8857eb8 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-# Copyright 2011 GRNET S.A. All rights reserved.
+# Copyright 2012 GRNET S.A. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or
 # without modification, are permitted provided that the following
@@ -37,9 +37,9 @@ 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_wth_progress, Silent, \
-                                                    Silent_wth_colors, error
-from image_creator.os_type import get_os_class
+from image_creator.output.cli import SilentOutput, SimpleOutput, \
+                                     OutputWthProgress
+from image_creator.os_type import os_cls
 from image_creator.kamaki_wrapper import Kamaki
 import sys
 import os
@@ -160,9 +160,10 @@ def image_creator():
                                                                 "must be set")
 
     if options.silent:
-        out = Silent_wth_colors() if sys.stdout.isatty() else Silent()
+        out = SilentOutput()
     else:
-        out = Output_wth_progress() if sys.stdout.isatty() else Output()
+        out = OutputWthProgress(True) if sys.stderr.isatty() else \
+                                                            SimpleOutput(False)
 
     title = 'snf-image-creator %s' % version
     out.output(title)
@@ -186,8 +187,8 @@ def image_creator():
         dev = disk.get_device(snapshot)
         dev.mount()
 
-        osclass = get_os_class(dev.distro, dev.ostype)
-        image_os = osclass(dev.root, dev.g, out)
+        cls = os_cls(dev.distro, dev.ostype)
+        image_os = cls(dev.root, dev.g, out)
         out.output()
 
         for sysprep in options.disabled_syspreps:
@@ -282,10 +283,8 @@ def main():
         ret = image_creator()
         sys.exit(ret)
     except FatalError as e:
-        if sys.stdout.isatty():
-            error(e)
-        else:
-            error(e, True, False)
+        colored = sys.stderr.isatty()
+        SimpleOutput(colored).error(e)
         sys.exit(1)