Revision a42a42b3 image_creator/dialog_main.py

b/image_creator/dialog_main.py
54 54
INPUTBOX_WIDTH = 70
55 55
CHECKBOX_WIDTH = 70
56 56
HELP_WIDTH = 70
57
INFOBOX_WIDTH = 70
57 58

  
58 59
CONFIGURATION_TASKS = [
59 60
 ("Partition table manipulation", ["FixPartitionTable"],
......
82 83

  
83 84

  
84 85
def confirm_reset(d):
85
    return not d.yesno(
86
        "Are you sure you want to reset everything?",
87
        width=YESNO_WIDTH)
86
    return not d.yesno("Are you sure you want to reset everything?",
87
                       width=YESNO_WIDTH)
88 88

  
89 89

  
90 90
def update_background_title(session):
......
94 94
    MB = 2 ** 20
95 95

  
96 96
    size = (dev.meta['SIZE'] + MB - 1) // MB
97
    title = "OS: %s, Distro: %s, Size: %dMB" % (dev.ostype, dev.distro, size)
97
    shrinked = 'shrinked' in session and session['shrinked'] == True
98
    postfix = " (shrinked)" if shrinked else ''
99

  
100
    title = "OS: %s, Distro: %s, Size: %dMB%s" % \
101
            (dev.ostype, dev.distro, size, postfix)
98 102

  
99 103
    d.setBackgroundTitle(title)
100 104

  
......
408 412

  
409 413
        (code, choice) = d.menu(
410 414
            "In this menu you can edit existing image properties or add new "
411
            "ones. Be carefull! Most properties have special meaning and "
415
            "ones. Be careful! Most properties have special meaning and "
412 416
            "alter the image deployment behaviour. Press <HELP> to see more "
413 417
            "information about image properties. Press <BACK> when done.",
414 418
            height=18, width=MENU_WIDTH, choices=choices, menu_height=10,
......
519 523
    d = session['dialog']
520 524
    image_os = session['image_os']
521 525

  
526
    # Is the image already shrinked?
527
    if 'shrinked' in session and session['shrinked'] == True:
528
        msg = "It seems you have shrinked the image. Running system " \
529
              "preparation tasks on a shrinked image is dangerous."
530

  
531
        if d.yesno("%s\n\nDo you really want to continue?" % msg,
532
                   width=YESNO_WIDTH, defaultno=1):
533
            return
534

  
522 535
    wrapper = textwrap.TextWrapper(width=65)
523 536

  
524 537
    help_title = "System Preperation Tasks"
......
531 544
    # Only give the user the choice between syspreps that have not ran yet
532 545
    syspreps = [s for s in all_syspreps if s not in session['exec_syspreps']]
533 546

  
547
    if len(syspreps) == 0:
548
        d.msgbox("No system preparation task left to run!", width=MSGBOX_WIDTH)
549
        return
550

  
534 551
    while 1:
535 552
        choices = []
536 553
        index = 0
......
576 593
                    image_os.out = out
577 594
                    image_os.do_sysprep()
578 595

  
596
                    for (k, v) in image_os.meta.items():
597
                        session['metadata'][str(k)] = str(v)
598

  
579 599
                    # Disable syspreps that have ran
580 600
                    for sysprep in session['exec_syspreps']:
581 601
                        image_os.disable_sysprep(sysprep)
......
588 608
            break
589 609

  
590 610

  
591
def customize_menu(session):
611
def shrink(session):
612
    d = session['dialog']
613
    dev = session['device']
614

  
615
    shrinked = 'shrinked' in session and session['shrinked'] == True
616

  
617
    if shrinked:
618
        d.msgbox("You have already shrinked your image!")
619
        return
620

  
621
    msg = "This operation will shrink the last partition of the image to " \
622
          "reduce the total image size. If the last partition is a swap " \
623
          "partition, then this partition is removed and the partition " \
624
          "before that is shrinked. The removed swap partition will be " \
625
          "recreated during image deployment."
626

  
627
    if not d.yesno("%s\n\nDo you want to continue?" % msg, width=70,
628
                   height=12, title="Image Shrinking"):
629
        dev.out = InfoBoxOutput(d, "Image Shrinking", height=3)
630
        session['metadata']['SIZE'] = str(dev.shrink())
631
        session['shrinked'] = True
632
        update_background_title(session)
633
        dev.out.finalize()
634

  
635

  
636
def customization_menu(session):
592 637
    d = session['dialog']
593 638

  
594 639
    choices = [("Sysprep", "Run various image preperation tasks"),
......
600 645
    default_item = "Sysprep"
601 646

  
602 647
    actions = {"Sysprep": sysprep,
648
               "Shrink": shrink,
603 649
               "View/Modify": modify_properties,
604 650
               "Delete": delete_properties,
605 651
               "Exclude": exclude_tasks}
......
631 677

  
632 678
    default_item = "Customize"
633 679

  
634
    actions = {"Customize": customize_menu, "Register": kamaki_menu,
680
    actions = {"Customize": customization_menu, "Register": kamaki_menu,
635 681
               "Extract": extract_image}
636 682
    while 1:
637 683
        (code, choice) = d.menu(
......
646 692
                break
647 693
        elif choice == "Reset":
648 694
            if confirm_reset(d):
649
                d.infobox("Resetting snf-image-creator. Please wait...")
695
                d.infobox("Resetting snf-image-creator. Please wait...",
696
                          width=INFOBOX_WIDTH)
650 697
                raise Reset
651 698
        elif choice in actions:
652 699
            actions[choice](session)
......
681 728
        sys.stderr.write("%s\n" % usage)
682 729
        return 1
683 730

  
731
    d.setBackgroundTitle('snf-image-creator')
732

  
684 733
    if os.geteuid() != 0:
685 734
        raise FatalError("You must run %s as root" % basename)
686 735

  
687 736
    media = select_file(d, sys.argv[1] if len(sys.argv) == 2 else None)
688 737

  
689
    d.setBackgroundTitle('snf-image-creator')
690

  
691 738
    out = GaugeOutput(d, "Initialization", "Initializing...")
692 739
    disk = Disk(media, out)
693 740

  
......
701 748
        dev = disk.get_device(snapshot)
702 749

  
703 750
        out.output("Collecting image metadata...")
704
        metadata = dev.meta
751

  
752
        metadata = {}
753
        for (key, value) in dev.meta.items():
754
            metadata[str(key)] = str(value)
755

  
705 756
        dev.mount(readonly=True)
706 757
        cls = os_cls(dev.distro, dev.ostype)
707 758
        image_os = cls(dev.root, dev.g, out)
708 759
        dev.umount()
709
        metadata.update(image_os.meta)
760

  
761
        for (key, value) in image_os.meta.items():
762
            metadata[str(key)] = str(value)
763

  
710 764
        out.success("done")
711 765
        out.cleanup()
712 766

  
......
748 802
                sys.exit(ret)
749 803
            except FatalError as e:
750 804
                msg = textwrap.fill(str(e), width=70)
751
                d.infobox(msg, width=70, title="Fatal Error")
805
                d.infobox(msg, width=INFOBOX_WIDTH, title="Fatal Error")
752 806
                sys.exit(1)
753 807
        except Reset:
754 808
            continue

Also available in: Unified diff