Add new windows sysprep for disabling hibernation
[snf-image-creator] / image_creator / dialog_menu.py
index ca9b323..9bc5c40 100644 (file)
@@ -327,6 +327,7 @@ def delete_clouds(session):
 
     (code, to_delete) = d.checklist("Choose which cloud accounts to delete:",
                                     choices=choices, width=WIDTH)
+    to_delete = map(lambda x: x.strip('"'), to_delete)  # Needed for OpenSUSE
 
     if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
         return False
@@ -538,6 +539,7 @@ def delete_properties(session):
 
     (code, to_delete) = d.checklist("Choose which properties to delete:",
                                     choices=choices, width=WIDTH)
+    to_delete = map(lambda x: x.strip('"'), to_delete)  # needed for OpenSUSE
 
     # If the user exits with ESC or CANCEL, the returned tag list is empty.
     for i in to_delete:
@@ -587,6 +589,7 @@ def exclude_tasks(session):
             choices=choices, height=19, list_height=8, width=WIDTH,
             help_button=1, extra_button=1, extra_label="No Config",
             title="Exclude Configuration Tasks")
+        tags = map(lambda x: x.strip('"'), tags)  # Needed for OpenSUSE
 
         if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
             return False
@@ -616,6 +619,41 @@ def exclude_tasks(session):
     return True
 
 
+def sysprep_params(session):
+
+    d = session['dialog']
+    image = session['image']
+
+    available = image.os.sysprep_params
+    needed = image.os.needed_sysprep_params()
+
+    if len(needed) == 0:
+        return True
+
+    fields = []
+    for param in needed:
+        default = available[param.name] if param.name in available else ""
+        fields.append(("%s: " % param.description, default, param.length))
+
+    txt = "Please provide the following system preparation parameters:"
+    code, output = d.form(txt, height=13, width=WIDTH, form_height=len(fields),
+                          fields=fields)
+
+    if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
+        return False
+
+    sysprep_params = {}
+    for i in range(len(fields)):
+        if needed[i].validator(output[i]):
+            image.os.sysprep_params[needed[i].name] = output[i]
+        else:
+            d.msgbox("The value you provided for parameter: %s is not valid" %
+                     name, width=SMALL_WIDTH)
+            return False
+
+    return True
+
+
 def sysprep(session):
     """Perform various system preperation tasks on the image"""
     d = session['dialog']
@@ -632,9 +670,6 @@ def sysprep(session):
 
     wrapper = textwrap.TextWrapper(width=WIDTH - 5)
 
-    help_title = "System Preperation Tasks"
-    sysprep_help = "%s\n%s\n\n" % (help_title, '=' * len(help_title))
-
     syspreps = image.os.list_syspreps()
 
     if len(syspreps) == 0:
@@ -645,6 +680,10 @@ def sysprep(session):
     while 1:
         choices = []
         index = 0
+
+        help_title = "System Preperation Tasks"
+        sysprep_help = "%s\n%s\n\n" % (help_title, '=' * len(help_title))
+
         for sysprep in syspreps:
             name, descr = image.os.sysprep_info(sysprep)
             display_name = name.replace('-', ' ').capitalize()
@@ -660,6 +699,7 @@ def sysprep(session):
             "run on the image. Press <Help> to see details about the system "
             "preparation tasks.", title="Run system preparation tasks",
             choices=choices, width=70, ok_label="Run", help_button=1)
+        tags = map(lambda x: x.strip('"'), tags)  # Needed for OpenSUSE
 
         if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
             return False
@@ -678,6 +718,9 @@ def sysprep(session):
                          title="System Preperation", width=SMALL_WIDTH)
                 continue
 
+            if not sysprep_params(session):
+                continue
+
             infobox = InfoBoxOutput(d, "Image Configuration")
             try:
                 image.out.add(infobox)