Revision b1395967 image_creator/disk.py

b/image_creator/disk.py
179 179

  
180 180
    def enable(self):
181 181
        """Enable a newly created DiskDevice"""
182
        new_progress = progress("Launching helper VM: ")
183
        self.progressbar = new_progress()
184
        self.progressbar.next()
182
        self.progressbar = progress("Launching helper VM: ", "percent")
183
        self.progressbar.max = 100
184
        self.progressbar.goto(1)
185 185
        eh = self.g.set_event_callback(self.progress_callback,
186 186
                                                    guestfs.EVENT_PROGRESS)
187 187
        self.g.launch()
188 188
        self.guestfs_enabled = True
189 189
        self.g.delete_event_callback(eh)
190 190
        if self.progressbar is not None:
191
            self.progressbar.send(100)
191
            output("\rLaunching helper VM...\033[K", False)
192
            success("done")
192 193
            self.progressbar = None
193 194

  
194 195
        output('Inspecting Operating System...', False)
......
217 218
        position = array[2]
218 219
        total = array[3]
219 220

  
220
        self.progressbar.send((position * 100) // total)
221

  
222
        if position == total:
223
            self.progressbar = None
221
        self.progressbar.goto((position * 100) // total)
224 222

  
225 223
    def mount(self):
226 224
        """Mount all disk partitions in a correct order."""
......
318 316
        blocksize = 2 ** 22  # 4MB
319 317
        size = self.size()
320 318
        progress_size = (size + 2 ** 20 - 1) // 2 ** 20  # in MB
321
        new_progress = progress("Dumping image file: ")
322
        progressbar = new_progress(progress_size)
319
        progressbar = progress("Dumping image file: ", 'mb')
320
        progressbar.max = progress_size
323 321
        source = open(self.device, "r")
324 322
        try:
325 323
            dest = open(outfile, "w")
......
333 331
                                                                        length)
334 332
                    offset += sent
335 333
                    left -= sent
336
                    for i in range((length + 2 ** 20 - 1) // 2 ** 20):
337
                        progressbar.next()
334
                    progressbar.goto((size - left) // 2 ** 20)
338 335
            finally:
339 336
                dest.close()
340 337
        finally:
341 338
            source.close()
342

  
343
        success('Image file %s was successfully created' % outfile)
339
        
340
        output("\rDumping image file...\033[K", False)
341
        success('image file %s was successfully created' % outfile)
344 342

  
345 343
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :

Also available in: Unified diff