Merge branch 'develop'
[snf-image-creator] / image_creator / dialog_menu.py
index 351f0b9..4f24b1e 100644 (file)
@@ -217,13 +217,26 @@ def register_image(session):
                  "register it", width=SMALL_WIDTH)
         return False
 
+    name = ""
+    description = session['metadata']['DESCRIPTION'] if 'DESCRIPTION' in \
+        session['metadata'] else ""
+
     while 1:
-        (code, answer) = d.inputbox("Please provide a registration name:",
-                                    width=WIDTH)
+        fields = [
+            ("Registration name:", name, 60),
+            ("Description (optional):", description, 80)]
+
+        (code, output) = d.form(
+            "Please provide the following registration info:", height=11,
+            width=WIDTH, form_height=2, fields=fields)
+
         if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
             return False
 
-        name = answer.strip()
+        name, description = output
+        name = name.strip()
+        description = description.strip()
+
         if len(name) == 0:
             d.msgbox("Registration name cannot be empty", width=SMALL_WIDTH)
             continue
@@ -238,6 +251,7 @@ def register_image(session):
 
         break
 
+    session['metadata']['DESCRIPTION'] = description
     metadata = {}
     metadata.update(session['metadata'])
     if 'task_metadata' in session:
@@ -488,6 +502,15 @@ def add_property(session):
     return True
 
 
+def show_properties_help(session):
+    """Show help for image properties"""
+    d = session['dialog']
+
+    help_file = get_help_file("image_properties")
+    assert os.path.exists(help_file)
+    d.textbox(help_file, title="Image Properties", width=70, height=40)
+
+
 def modify_properties(session):
     """Modify an existing image property"""
     d = session['dialog']
@@ -497,6 +520,19 @@ def modify_properties(session):
         for (key, val) in session['metadata'].items():
             choices.append((str(key), str(val)))
 
+        if len(choices) == 0:
+            code = d.yesno(
+                "No image properties are available. "
+                "Would you like to add a new one?", width=WIDTH, help_button=1)
+            if code == d.DIALOG_OK:
+                if not add_property(session):
+                    return True
+            elif code == d.DIALOG_CANCEL:
+                return True
+            elif code == d.DIALOG_HELP:
+                show_properties_help(session)
+            continue
+
         (code, choice) = d.menu(
             "In this menu you can edit existing image properties or add new "
             "ones. Be careful! Most properties have special meaning and "
@@ -526,9 +562,7 @@ def modify_properties(session):
         elif code == d.DIALOG_EXTRA:
             add_property(session)
         elif code == 'help':
-            help_file = get_help_file("image_properties")
-            assert os.path.exists(help_file)
-            d.textbox(help_file, title="Image Properties", width=70, height=40)
+            show_properties_help(session)
 
 
 def delete_properties(session):
@@ -539,6 +573,11 @@ def delete_properties(session):
     for (key, val) in session['metadata'].items():
         choices.append((key, "%s" % val, 0))
 
+    if len(choices) == 0:
+        d.msgbox("No available images properties to delete!",
+                 width=SMALL_WIDTH)
+        return True
+
     (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
@@ -558,6 +597,12 @@ def delete_properties(session):
 def exclude_tasks(session):
     """Exclude specific tasks from running during image deployment"""
     d = session['dialog']
+    image = session['image']
+
+    if image.is_unsupported():
+        d.msgbox("Image deployment configuration is disabled for unsupported "
+                 "images.", width=SMALL_WIDTH)
+        return False
 
     index = 0
     displayed_index = 1