Update version.py and ChangeLog for 0.6.1
[snf-image-creator] / image_creator / dialog_wizard.py
index e5a39f8..ffabecf 100644 (file)
@@ -49,6 +49,7 @@ from image_creator.dialog_util import extract_image, update_background_title, \
 
 PAGE_WIDTH = 70
 PAGE_HEIGHT = 10
+SYSPREP_PARAM_MAXLEN = 20
 
 
 class WizardExit(Exception):
@@ -221,7 +222,7 @@ class WizardFormPage(WizardPage):
 
         field_lenght = len(self.fields())
         form_height = field_lenght if field_lenght < PAGE_HEIGHT - 4 \
-            else PAGET_HEIGHT - 4
+            else PAGE_HEIGHT - 4
 
         (code, output) = d.form(
             self.text, width=PAGE_WIDTH, height=PAGE_HEIGHT,
@@ -334,26 +335,33 @@ def start_wizard(session):
         if 'DESCRIPTION' in session['metadata'] else '')
 
     # Create Sysprep Params Wizard Page
-    needed = image.os.needed_sysprep_params()
+    needed = image.os.needed_sysprep_params
+    # Only show the parameters that don't have default values
+    param_names = [param for param in needed if needed[param].default is None]
 
     def sysprep_params_fields():
         fields = []
         available = image.os.sysprep_params
-        for param in needed:
-            text = param.description
-            default = available[param.name] if param.name in available else ""
-            fields.append(("%s: " % text, default, param.length))
+        for name in param_names:
+            text = needed[name].description
+            default = str(available[name]) if name in available else ""
+            fields.append(("%s: " % text, default, SYSPREP_PARAM_MAXLEN))
         return fields
 
     def sysprep_params_validate(answer):
         params = {}
         for i in range(len(answer)):
-            if needed[i].validator(answer):
-                params[needed[i].name] = answer[i]
-            else:
-                session['dialog'].msgbox("Invalid value for parameter `%s'" %
-                                         needed[i].name)
-                raise WizardReloadPage
+            try:
+                value = needed[param_names[i]].type(answer[i])
+                if needed[param_names[i]].validate(value):
+                    params[param_names[i]] = value
+                    continue
+            except ValueError:
+                pass
+
+            session['dialog'].msgbox("Invalid value for parameter `%s'" %
+                                     param_names[i])
+            raise WizardReloadPage
         return params
 
     def sysprep_params_display(params):
@@ -406,7 +414,8 @@ def create_image(session):
         out.clear()
 
         #Sysprep
-        image.os.sysprep_params.update(wizard['SysprepParams'])
+        if 'SysprepParams' in wizard:
+            image.os.sysprep_params.update(wizard['SysprepParams'])
         image.os.do_sysprep()
         metadata = image.os.meta