From: Nikos Skalkotos Date: Wed, 9 Oct 2013 13:44:45 +0000 (+0300) Subject: Fix a crash in dialog menu X-Git-Tag: 0.5.3~2 X-Git-Url: https://code.grnet.gr/git/snf-image-creator/commitdiff_plain/6ca82c228121c9b89bfdc458b92b37aee722a9c2 Fix a crash in dialog menu The program would crash if no image properties were available and the user chose "Edit properties" or "Delete Properties" in the customization menu --- diff --git a/image_creator/dialog_menu.py b/image_creator/dialog_menu.py index 351f0b9..25fcb6c 100644 --- a/image_creator/dialog_menu.py +++ b/image_creator/dialog_menu.py @@ -488,6 +488,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 +506,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 +548,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 +559,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