Fix a bug in kamaki menu code
[snf-image-creator] / image_creator / dialog_wizard.py
index f283320..f61197d 100644 (file)
@@ -186,7 +186,7 @@ def wizard(session):
         "Please provide your ~okeanos account token:",
         title="~okeanos account token", init=Kamaki.get_token())
 
-    msg = "Do you wish to continue with the image extraction process?"
+    msg = "All necessary information has been gathered. Confirm and Proceed."
     proceed = WizardYesNoPage(msg, title="Confirmation")
 
     w = Wizard(session)
@@ -213,66 +213,70 @@ def extract_image(session):
     image_os = session['image_os']
     wizard = session['wizard']
 
-    out = OutputWthProgress(True)
-    #Initialize the output
-    disk.out = out
-    device.out = out
-    image_os.out = out
-
-    out.clear()
+    with_progress = OutputWthProgress(True)
+    out = disk.out
+    out.add(with_progress)
+    try:
+        out.clear()
 
-    #Sysprep
-    device.mount(False)
-    image_os.do_sysprep()
-    metadata = image_os.meta
-    device.umount()
+        #Sysprep
+        device.mount(False)
+        image_os.do_sysprep()
+        metadata = image_os.meta
+        device.umount()
 
-    #Shrink
-    size = device.shrink()
+        #Shrink
+        size = device.shrink()
+        session['shrinked'] = True
+        getattr(__import__("image_creator.dialog_main",
+                fromlist=['image_creator']),
+                "update_background_title")(session)
 
-    metadata.update(device.meta)
-    metadata['DESCRIPTION'] = wizard['ImageDescription']
+        metadata.update(device.meta)
+        metadata['DESCRIPTION'] = wizard['ImageDescription']
 
-    #MD5
-    md5 = MD5(out)
-    session['checksum'] = md5.compute(snapshot, size)
+        #MD5
+        md5 = MD5(out)
+        session['checksum'] = md5.compute(snapshot, size)
 
-    #Metadata
-    metastring = '\n'.join(
-        ['%s=%s' % (key, value) for (key, value) in metadata.items()])
-    metastring += '\n'
+        #Metadata
+        metastring = '\n'.join(
+            ['%s=%s' % (key, value) for (key, value) in metadata.items()])
+        metastring += '\n'
 
-    out.output()
-    try:
-        out.output("Uploading image to pithos:")
-        kamaki = Kamaki(wizard['account'], wizard['token'], out)
-
-        name = "%s-%s.diskdump" % (wizard['ImageName'],
-                                   time.strftime("%Y%m%d%H%M"))
-        pithos_file = ""
-        with open(snapshot, 'rb') as f:
-            pithos_file = kamaki.upload(f, size, name,
-                                         "(1/4)  Calculating block hashes",
-                                         "(2/4)  Uploading missing blocks")
-
-        out.output("(3/4)  Uploading metadata file...", False)
-        kamaki.upload(StringIO.StringIO(metastring), size=len(metastring),
-                      remote_path="%s.%s" % (name, 'meta'))
-        out.success('done')
-        out.output("(4/4)  Uploading md5sum file...", False)
-        md5sumstr = '%s %s\n' % (session['checksum'], name)
-        kamaki.upload(StringIO.StringIO(md5sumstr), size=len(md5sumstr),
-                      remote_path="%s.%s" % (name, 'md5sum'))
-        out.success('done')
         out.output()
-
-        out.output('Registring image to ~okeanos...', False)
-        kamaki.register(wizard['ImageName'], pithos_file, metadata)
-        out.success('done')
-        out.output()
-
-    except ClientError as e:
-        raise FatalError("Pithos client: %d %s" % (e.status, e.message))
+        try:
+            out.output("Uploading image to pithos:")
+            kamaki = Kamaki(wizard['account'], wizard['token'], out)
+
+            name = "%s-%s.diskdump" % (wizard['ImageName'],
+                                       time.strftime("%Y%m%d%H%M"))
+            pithos_file = ""
+            with open(snapshot, 'rb') as f:
+                pithos_file = kamaki.upload(f, size, name,
+                                             "(1/4)  Calculating block hashes",
+                                             "(2/4)  Uploading missing blocks")
+
+            out.output("(3/4)  Uploading metadata file...", False)
+            kamaki.upload(StringIO.StringIO(metastring), size=len(metastring),
+                          remote_path="%s.%s" % (name, 'meta'))
+            out.success('done')
+            out.output("(4/4)  Uploading md5sum file...", False)
+            md5sumstr = '%s %s\n' % (session['checksum'], name)
+            kamaki.upload(StringIO.StringIO(md5sumstr), size=len(md5sumstr),
+                          remote_path="%s.%s" % (name, 'md5sum'))
+            out.success('done')
+            out.output()
+
+            out.output('Registring image to ~okeanos...', False)
+            kamaki.register(wizard['ImageName'], pithos_file, metadata)
+            out.success('done')
+            out.output()
+
+        except ClientError as e:
+            raise FatalError("Pithos client: %d %s" % (e.status, e.message))
+    finally:
+        out.remove(with_progress)
 
     msg = "The image was successfully uploaded and registered to " \
           "~okeanos. Would you like to keep a local copy of the image?"