Skip to content
Snippets Groups Projects
dialog_menu.py 38.9 KiB
Newer Older
def show_log(session):
    """Show the current execution log"""

    d = session['dialog']
    log = session['image'].out[0].stderr

    log.file.flush()

    while 1:
        code = d.textbox(log.name, title="Log", width=70, height=40,
                         extra_button=1, extra_label="Save", ok_label="Close")
            while 1:
                path = select_file(d, title="Save log as...")
                if path is None:
                    break
                if os.path.isdir(path):
                    continue

                if copy_file(d, log.name, path):
                    break
        else:
            return


def customization_menu(session):
Nikos Skalkotos's avatar
Nikos Skalkotos committed
    """Show image customization menu"""
    d = session['dialog']
    image = session['image']
    if image.mount_local_support:
        choices.append(("Mount", "Mount image on the local file system"))
    if hasattr(image.os, "install_virtio_drivers"):
        choices.append(("VirtIO", "Install or update the VirtIO drivers"))
        [("Sysprep", "Run various image preparation tasks"),
         ("Properties", "View & Modify image properties"),
         ("Exclude", "Exclude various deployment tasks from running")])
    actions = {"Mount": mount,
               "VirtIO": virtio,
               "Sysprep": sysprep,
               "Properties": modify_properties,
               "Exclude": exclude_tasks}
    while 1:
        (code, choice) = d.menu(
            text="Choose one of the following or press <Back> to exit.",
            width=WIDTH, choices=choices, cancel="Back", height=13,
            menu_height=len(choices), default_item=choices[default_item][0],
            title="Image Customization Menu")

        if code in (d.CANCEL, d.ESC):
            break
        elif choice in actions:
            default_item = [entry[0] for entry in choices].index(choice)
            if actions[choice](session):
                default_item = (default_item + 1) % len(choices)


def main_menu(session):
Nikos Skalkotos's avatar
Nikos Skalkotos committed
    """Show the main menu of the program"""
    d = session['dialog']

    update_background_title(session)

Nikos Skalkotos's avatar
Nikos Skalkotos committed
    choices = [("Customize", "Customize image & cloud deployment options"),
               ("Register", "Register image to a cloud"),
               ("Extract", "Dump image to local file system"),
               ("Log", "Show current execution log"),
               ("Reset", "Reset everything and start over again"),
               ("Help", "Get help for using snf-image-creator")]

    default_item = "Customize"

    actions = {"Customize": customization_menu, "Register": kamaki_menu,
               "Extract": extract_image, "Log": show_log}
    title = "Image Creator for Synnefo (snf-image-creator v%s)" % version
    while 1:
        (code, choice) = d.menu(
            text="Choose one of the following or press <Exit> to exit.",
            width=WIDTH, choices=choices, cancel="Exit", height=13,
            default_item=default_item, menu_height=len(choices),
            title=title)
        if code in (d.CANCEL, d.ESC):
            if confirm_exit(d):
                break
        elif choice == "Reset":
            if confirm_reset(d):
Nikos Skalkotos's avatar
Nikos Skalkotos committed
                d.infobox("Resetting snf-image-creator. Please wait ...",
                          width=SMALL_WIDTH)
                raise Reset
        elif choice == "Help":
            d.msgbox("For help, check the online documentation:\n\nhttp://www"
                     ".synnefo.org/docs/snf-image-creator/latest/",
                     width=WIDTH, title="Help")
        elif choice in actions:
            actions[choice](session)

        if len(choice):
            default_item = choice

# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :