Revision 8e3065a0

b/image_creator/disk.py
179 179

  
180 180
    def enable(self):
181 181
        """Enable a newly created DiskDevice"""
182
        self.progressbar = progress("Launching helper VM: ")
182
        new_progress = progress("Launching helper VM: ")
183
        self.progressbar = new_progress()
183 184
        self.progressbar.next()
184 185
        eh = self.g.set_event_callback(self.progress_callback,
185 186
                                                    guestfs.EVENT_PROGRESS)
......
317 318
        blocksize = 2 ** 22  # 4MB
318 319
        size = self.size()
319 320
        progress_size = (size + 2 ** 20 - 1) // 2 ** 20  # in MB
320
        progressbar = progress("Dumping image file: ", progress_size)
321

  
321
        new_progress = progress("Dumping image file: ")
322
        progressbar = new_progress(progress_size)
322 323
        source = open(self.device, "r")
323 324
        try:
324 325
            dest = open(outfile, "w")
b/image_creator/kamaki_wrapper.py
38 38
from kamaki.clients.image import ImageClient
39 39
from kamaki.clients.pithos import PithosClient
40 40

  
41
from image_creator.util import FatalError
41
from image_creator.util import FatalError, progress
42 42

  
43 43
CONTAINER = "images"
44 44

  
......
73 73
                    raise FatalError("Pithos client: %d %s" % \
74 74
                                                        (e.status, e.message))
75 75
            try:
76
                self.pithos_client.create_object(remote_path, f, size)
76
		hash_progress = progress("(1/2)  Calculating block hashes:")
77
		upload_progress = progress("(2/2)  Uploading missing blocks:")
78
                self.pithos_client.create_object(remote_path, f, size,
79
						hash_progress, upload_progress)
77 80
                self.uploaded_object = "pithos://%s/%s/%s" % \
78 81
                                (self.account, self.container, remote_path)
79 82
            except ClientError as e:
b/image_creator/main.py
37 37
from image_creator import __version__ as version
38 38
from image_creator import util
39 39
from image_creator.disk import Disk
40
from image_creator.util import get_command, error, success, output, FatalError
40
from image_creator.util import get_command, error, success, output, \
41
                                                    FatalError, progress, md5
41 42
from image_creator.kamaki_wrapper import Kamaki
42 43
import sys
43 44
import os
......
153 154
                        % os.path.basename(sys.argv[0]))
154 155

  
155 156
    if not options.force and options.outfile is not None:
156
        for extension in ('', '.meta'):
157
        for extension in ('', '.meta', '.md5sum'):
157 158
            filename = "%s%s" % (options.outfile, extension)
158 159
            if os.path.exists(filename):
159 160
                raise FatalError("Output file %s exists "
......
193 194
        size = options.shrink and dev.shrink() or dev.size()
194 195
        metadata['SIZE'] = str(size // 2 ** 20)
195 196

  
197
        #Calculating MD5sum
198
        output("Calculating md5sum...", False)
199
        checksum = md5(snapshot, size)
200
        success(checksum)
201
        output()
202

  
196 203
        if options.outfile is not None:
197 204
            f = open('%s.%s' % (options.outfile, 'meta'), 'w')
198 205
            try:
......
207 214
        disk.destroy_device(dev)
208 215

  
209 216
        if options.upload:
210
            output("Uploading image to pithos...", False)
217
            output("Uploading image to pithos:")
211 218
            kamaki = Kamaki(options.account, options.token)
212 219
            kamaki.upload(snapshot, size, options.upload)
213
            output("done")
214 220

  
215 221
    finally:
216 222
        output('cleaning up...')
b/image_creator/util.py
33 33

  
34 34
import sys
35 35
import pbs
36
import hashlib
36 37
from clint.textui import colored, progress as uiprogress
37 38

  
38 39

  
......
84 85
            sys.stdout.flush()
85 86

  
86 87

  
87
def progress(label='', n=100):
88
def progress(message=''):
88 89

  
89 90
    PROGRESS_LENGTH = 32
90 91
    MESSAGE_LENGTH = 32
91 92

  
92
    def progress_generator(label, n):
93
    def progress_generator(n=100):
93 94
        position = 0
94
        for i in uiprogress.bar(range(n), label.ljust(MESSAGE_LENGTH), \
95
                                                    PROGRESS_LENGTH, silent):
95
        msg = message.ljust(MESSAGE_LENGTH)
96
        for i in uiprogress.bar(range(n), msg, PROGRESS_LENGTH, silent):
96 97
            if i < position:
97 98
                continue
98 99
            position = yield
99 100
        yield  # suppress the StopIteration exception
100
    return progress_generator(label, n)
101
    return progress_generator
102

  
103
def md5(filename, size, progress = None):
104

  
105
    BLOCKSIZE = 2^22  # 4MB
106

  
107
    md5 = hashlib.md5()
108
    with open(filename, "r") as src:
109
        left = size
110
        while left > 0:
111
            length = min(left, BLOCKSIZE)
112
            data = src.read(length)
113
            md5.update(data)
114
            left -= length
115

  
116
    return md5.hexdigest()
101 117

  
102 118
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :

Also available in: Unified diff