Add size param in the Output.Progress constructor
[snf-image-creator] / image_creator / output.py
index 51312e1..040029c 100644 (file)
@@ -70,6 +70,7 @@ def output(msg='', new_line=True):
 
 
 class Output(object):
+
     def error(self, msg, new_line=True):
         error(msg, new_line, False)
 
@@ -82,9 +83,17 @@ class Output(object):
     def output(self, msg='', new_line=True):
         output(msg, new_line)
 
-    class Progress(object):
-        def __init__(self, title, bar_type='default'):
-            output("%s..." % title, False)
+    def _get_progress(self):
+        progress = self._Progress
+        progress.output = self
+        return progress
+
+    Progress = property(_get_progress)
+
+    class _Progress(object):
+        def __init__(self, size, title, bar_type='default'):
+            self.output.output("%s..." % title, False)
+            self.size = size
 
         def goto(self, dest):
             pass
@@ -93,7 +102,7 @@ class Output(object):
             pass
 
         def success(self, result):
-            sucess(result)
+            self.output.success(result)
 
     def progress_generator(self, message):
         def generator(n):
@@ -121,7 +130,7 @@ class Output_wth_colors(Output):
 
 
 class Output_wth_progress(Output_wth_colors):
-    class Progress(Bar):
+    class _Progress(Bar):
         MESSAGE_LENGTH = 30
 
         template = {
@@ -132,18 +141,22 @@ class Output_wth_progress(Output_wth_colors):
             'mb': '%(index)d/%(max)d MB'
         }
 
-        def __init__(self, title, bar_type='default'):
-            super(Output_wth_progress.Progress, self).__init__()
+        def __init__(self, size, title, bar_type='default'):
+            super(Output_wth_progress._Progress, self).__init__()
             self.title = title
             self.fill = '#'
             self.bar_prefix = ' ['
             self.bar_suffix = '] '
             self.message = ("%s:" % self.title).ljust(self.MESSAGE_LENGTH)
             self.suffix = self.template[bar_type]
+            self.max = size
+
+            # print empty progress bar workaround
+            self.goto(1)
 
         def success(self, result):
-            output("\r%s... \033[K" % self.title, False)
-            success(result)
+            self.output.output("\r%s... \033[K" % self.title, False)
+            self.output.success(result)
 
 
 class Silent(Output):
@@ -156,12 +169,6 @@ class Silent(Output):
     def output(self, msg='', new_line=True):
         pass
 
-    class Progress(Output.Progress):
-        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):