Revision 1f42adc8 image_creator/dialog_main.py
b/image_creator/dialog_main.py | ||
---|---|---|
57 | 57 |
INFOBOX_WIDTH = 70 |
58 | 58 |
|
59 | 59 |
CONFIGURATION_TASKS = [ |
60 |
("Partition table manipulation", ["FixPartitionTable"], |
|
61 |
["linux", "windows"]), |
|
62 |
("File system resize", |
|
63 |
["FilesystemResizeUnmounted", "FilesystemResizeMounted"], |
|
64 |
["linux", "windows"]), |
|
65 |
("Swap partition configuration", ["AddSwap"], ["linux"]), |
|
66 |
("SSH keys removal", ["DeleteSSHKeys"], ["linux"]), |
|
67 |
("Temporal RDP disabling", ["DisableRemoteDesktopConnections"], ["windows"]),
|
|
68 |
("SELinux relabeling at next boot", ["SELinuxAutorelabel"],
|
|
69 |
["linux"]), |
|
70 |
("Hostname/Computer Name assignment", ["AssignHostname"], |
|
71 |
["windows", "linux"]), |
|
72 |
("Password change", ["ChangePassword"], ["windows", "linux"]), |
|
73 |
("File injection", ["EnforcePersonality"], ["windows", "linux"]) |
|
60 |
("Partition table manipulation", ["FixPartitionTable"],
|
|
61 |
["linux", "windows"]),
|
|
62 |
("File system resize",
|
|
63 |
["FilesystemResizeUnmounted", "FilesystemResizeMounted"],
|
|
64 |
["linux", "windows"]),
|
|
65 |
("Swap partition configuration", ["AddSwap"], ["linux"]),
|
|
66 |
("SSH keys removal", ["DeleteSSHKeys"], ["linux"]),
|
|
67 |
("Temporal RDP disabling", ["DisableRemoteDesktopConnections"],
|
|
68 |
["windows"]),
|
|
69 |
("SELinux relabeling at next boot", ["SELinuxAutorelabel"], ["linux"]),
|
|
70 |
("Hostname/Computer Name assignment", ["AssignHostname"],
|
|
71 |
["windows", "linux"]),
|
|
72 |
("Password change", ["ChangePassword"], ["windows", "linux"]),
|
|
73 |
("File injection", ["EnforcePersonality"], ["windows", "linux"])
|
|
74 | 74 |
] |
75 | 75 |
|
76 | 76 |
|
... | ... | |
186 | 186 |
|
187 | 187 |
if len(overwrite) > 0: |
188 | 188 |
if d.yesno("The following file(s) exist:\n" |
189 |
"%s\nDo you want to overwrite them?" %
|
|
190 |
"\n".join(overwrite), width=YESNO_WIDTH):
|
|
189 |
"%s\nDo you want to overwrite them?" % |
|
190 |
"\n".join(overwrite), width=YESNO_WIDTH): |
|
191 | 191 |
continue |
192 | 192 |
|
193 | 193 |
out = GaugeOutput(d, "Image Extraction", "Extracting image...") |
... | ... | |
322 | 322 |
return False |
323 | 323 |
|
324 | 324 |
while 1: |
325 |
(code, answer) = d.inputbox("Please provide a registration name:" |
|
326 |
" be registered:", width=INPUTBOX_WIDTH)
|
|
325 |
(code, answer) = d.inputbox("Please provide a registration name:",
|
|
326 |
width=INPUTBOX_WIDTH)
|
|
327 | 327 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
328 | 328 |
return False |
329 | 329 |
|
... | ... | |
428 | 428 |
|
429 | 429 |
while 1: |
430 | 430 |
(code, answer) = d.inputbox("Please provide a value for image " |
431 |
"property %s" % name, width=INPUTBOX_WIDTH) |
|
431 |
"property %s" % name, width=INPUTBOX_WIDTH)
|
|
432 | 432 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
433 | 433 |
return False |
434 | 434 |
|
... | ... | |
462 | 462 |
help_button=1, title="Image Properties") |
463 | 463 |
|
464 | 464 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
465 |
break
|
|
465 |
return True
|
|
466 | 466 |
# Edit button |
467 | 467 |
elif code == d.DIALOG_OK: |
468 |
(code, answer) = d.inputbox("Please provide a new value for " |
|
469 |
"the image property with name `%s':" % choice, |
|
470 |
init=session['metadata'][choice], width=INPUTBOX_WIDTH) |
|
468 |
(code, answer) = d.inputbox("Please provide a new value for the " |
|
469 |
"image property with name `%s':" % |
|
470 |
choice, |
|
471 |
init=session['metadata'][choice], |
|
472 |
width=INPUTBOX_WIDTH) |
|
471 | 473 |
if code not in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
472 | 474 |
value = answer.strip() |
473 | 475 |
if len(value) == 0: |
... | ... | |
497 | 499 |
cnt = len(to_delete) |
498 | 500 |
if cnt > 0: |
499 | 501 |
d.msgbox("%d image properties were deleted." % cnt, width=MSGBOX_WIDTH) |
502 |
return True |
|
503 |
else: |
|
504 |
return False |
|
500 | 505 |
|
501 | 506 |
|
502 | 507 |
def exclude_tasks(session): |
... | ... | |
514 | 519 |
"Do you wish to enable it?", width=YESNO_WIDTH): |
515 | 520 |
session['excluded_tasks'].remove(-1) |
516 | 521 |
else: |
517 |
return |
|
522 |
return False
|
|
518 | 523 |
|
519 | 524 |
for (msg, task, osfamily) in CONFIGURATION_TASKS: |
520 | 525 |
if session['metadata']['OSFAMILY'] in osfamily: |
... | ... | |
536 | 541 |
title="Exclude Configuration Tasks") |
537 | 542 |
|
538 | 543 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
539 |
break
|
|
544 |
return False
|
|
540 | 545 |
elif code == d.DIALOG_HELP: |
541 | 546 |
help_file = get_help_file("configuration_tasks") |
542 | 547 |
assert os.path.exists(help_file) |
... | ... | |
556 | 561 |
for task in session['excluded_tasks']: |
557 | 562 |
exclude_metadata.extend(CONFIGURATION_TASKS[task][1]) |
558 | 563 |
|
559 |
session['task_metadata'] = \
|
|
560 |
map(lambda x: "EXCLUDE_TASK_%s" % x, exclude_metadata)
|
|
564 |
session['task_metadata'] = map(lambda x: "EXCLUDE_TASK_%s" % x,
|
|
565 |
exclude_metadata)
|
|
561 | 566 |
break |
562 | 567 |
|
568 |
return True |
|
569 |
|
|
563 | 570 |
|
564 | 571 |
def sysprep(session): |
565 | 572 |
d = session['dialog'] |
... | ... | |
610 | 617 |
choices=choices, width=70, ok_label="Run", help_button=1) |
611 | 618 |
|
612 | 619 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
613 |
break
|
|
620 |
return False
|
|
614 | 621 |
elif code == d.DIALOG_HELP: |
615 | 622 |
d.scrollbox(sysprep_help, width=HELP_WIDTH) |
616 | 623 |
elif code == d.DIALOG_OK: |
... | ... | |
647 | 654 |
finally: |
648 | 655 |
out.cleanup() |
649 | 656 |
break |
657 |
return True |
|
650 | 658 |
|
651 | 659 |
|
652 | 660 |
def shrink(session): |
... | ... | |
657 | 665 |
|
658 | 666 |
if shrinked: |
659 | 667 |
d.msgbox("You have already shrinked your image!") |
660 |
return |
|
668 |
return True
|
|
661 | 669 |
|
662 | 670 |
msg = "This operation will shrink the last partition of the image to " \ |
663 | 671 |
"reduce the total image size. If the last partition is a swap " \ |
... | ... | |
667 | 675 |
|
668 | 676 |
if not d.yesno("%s\n\nDo you want to continue?" % msg, width=70, |
669 | 677 |
height=12, title="Image Shrinking"): |
670 |
|
|
671 | 678 |
with metadata_monitor(session, dev.meta): |
672 | 679 |
dev.out = InfoBoxOutput(d, "Image Shrinking", height=3) |
673 | 680 |
dev.shrink() |
... | ... | |
675 | 682 |
|
676 | 683 |
session['shrinked'] = True |
677 | 684 |
update_background_title(session) |
685 |
else: |
|
686 |
return False |
|
687 |
|
|
688 |
return True |
|
678 | 689 |
|
679 | 690 |
|
680 | 691 |
def customization_menu(session): |
... | ... | |
686 | 697 |
("Delete", "Delete image properties"), |
687 | 698 |
("Exclude", "Exclude various deployment tasks from running")] |
688 | 699 |
|
689 |
default_item = "Sysprep"
|
|
700 |
default_item = 0
|
|
690 | 701 |
|
691 | 702 |
actions = {"Sysprep": sysprep, |
692 | 703 |
"Shrink": shrink, |
... | ... | |
697 | 708 |
(code, choice) = d.menu( |
698 | 709 |
text="Choose one of the following or press <Back> to exit.", |
699 | 710 |
width=MENU_WIDTH, choices=choices, cancel="Back", height=13, |
700 |
menu_height=len(choices), default_item=default_item,
|
|
711 |
menu_height=len(choices), default_item=choices[default_item][0],
|
|
701 | 712 |
title="Image Customization Menu") |
702 | 713 |
|
703 | 714 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
704 | 715 |
break |
705 | 716 |
elif choice in actions: |
706 |
default_item = choice |
|
707 |
actions[choice](session) |
|
717 |
default_item = [entry[0] for entry in choices].index(choice) |
|
718 |
if actions[choice](session): |
|
719 |
default_item = (default_item + 1) % len(choices) |
|
708 | 720 |
|
709 | 721 |
|
710 | 722 |
def main_menu(session): |
... | ... | |
754 | 766 |
break |
755 | 767 |
|
756 | 768 |
(code, media) = d.fselect(root, 10, 50, |
757 |
title="Please select input media") |
|
769 |
title="Please select input media")
|
|
758 | 770 |
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC): |
759 | 771 |
if confirm_exit(d, "You canceled the media selection dialog box."): |
760 | 772 |
sys.exit(0) |
Also available in: Unified diff