def enable(self):
"""Enable a newly created DiskDevice"""
- self.progressbar = self.out.Progress("Launching helper VM", "percent")
- self.progressbar.max = 100
- self.progressbar.goto(1)
+ self.progressbar = self.out.Progress(100, "Launching helper VM",
+ "percent")
eh = self.g.set_event_callback(self.progress_callback,
guestfs.EVENT_PROGRESS)
self.g.launch()
MB = 2 ** 20
blocksize = 4 * MB # 4MB
size = self.meta['SIZE']
- progress_size = (size + MB - 1) // MB # in MB
- progressbar = self.out.Progress("Dumping image file", 'mb')
- progressbar.max = progress_size
+ progr_size = (size + MB - 1) // MB # in MB
+ progressbar = self.out.Progress(progr_size, "Dumping image file", 'mb')
with open(self.real_device, 'r') as src:
with open(outfile, "w") as dst:
Progress = property(_get_progress)
class _Progress(object):
- def __init__(self, title, bar_type='default'):
+ def __init__(self, size, title, bar_type='default'):
self.output.output("%s..." % title, False)
+ self.size = size
def goto(self, dest):
pass
'mb': '%(index)d/%(max)d MB'
}
- def __init__(self, title, bar_type='default'):
+ def __init__(self, size, title, bar_type='default'):
super(Output_wth_progress._Progress, self).__init__()
self.title = title
self.fill = '#'
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):
self.output.output("\r%s... \033[K" % self.title, False)
def compute(self, filename, size):
- BLOCKSIZE = 2 ** 22 # 4MB
+ MB = 2 ** 20
+ BLOCKSIZE = 4 * MB # 4MB
- progressbar = self.out.Progress("Calculating md5sum:", 'mb')
- progressbar.max = ((size + 2 ** 20 - 1) // (2 ** 20))
+ prog_size = ((size + MB - 1) // MB) # in MB
+ progressbar = self.out.Progress(prog_size, "Calculating md5sum:", 'mb')
md5 = hashlib.md5()
with open(filename, "r") as src:
left = size
data = src.read(length)
md5.update(data)
left -= length
- progressbar.goto((size - left) // (2 ** 20))
+ progressbar.goto((size - left) // MB)
checksum = md5.hexdigest()
progressbar.success(checksum)