display build progress as number of packages
authorTimo Savola <tsavola@movial.fi>
Tue, 5 Aug 2008 12:42:11 +0000 (15:42 +0300)
committerTimo Savola <tsavola@movial.fi>
Tue, 5 Aug 2008 12:42:11 +0000 (15:42 +0300)
matrix/build.py

index 9a0c9f1..0621240 100644 (file)
@@ -131,7 +131,7 @@ class Builder(object):
                self.wait_install = []
                self.in_install = None
 
-               self.progress = Progress(count * 2)
+               self.progress = Progress(count)
 
                self.error = False
 
@@ -209,6 +209,8 @@ class Builder(object):
 
                if status:
                        self.error = True
+                       if config.keep_going:
+                               self.progress.clear_max()
 
                c = self.jobs[pid]
                del self.jobs[pid]
@@ -219,7 +221,6 @@ class Builder(object):
                                log.error('Failed to build %s' % c.name)
                                return
 
-                       self.progress.increment()
                        if config.debug:
                                print 'Built', c
 
@@ -259,16 +260,21 @@ class Builder(object):
 class Progress(object):
        def __init__(self, max):
                self.now = 0
-               self.max = max
                self.file = sys.stdout
 
+               self.max_width = len(str(max))
+               self.format = '%%%dd/%d ' % (self.max_width, max)
+
                self.newline = True
 
+       def clear_max(self):
+               self.format = '%%%dd %s ' % (self.max_width, ' ' * self.max_width)
+
        def increment(self):
                self.now += 1
 
        def write(self, str):
-               progress = '%3d%% ' % (self.now * 100 / self.max)
+               progress = self.format % self.now
 
                while str:
                        if self.newline: