installer/packageselector.py
f4d17450
 #!/usr/bin/python2
 #
 #    Copyright (C) 2015 vmware inc.
 #
 #    Author: Mahmoud Bassiouny <mbassiouny@vmware.com>
 
 import json
5d05cfcc
 import os
f4d17450
 import curses
 from sets import Set
 from jsonwrapper import JsonWrapper
 from menu import Menu
 from window import Window
 from actionresult import ActionResult
 
 class PackageSelector(object):
5d05cfcc
     def __init__(self,  maxy, maxx, install_config, options_file):
f4d17450
         self.install_config = install_config
         self.maxx = maxx
         self.maxy = maxy
         self.win_width = 50
4d53ba03
         self.win_height = 13
f4d17450
 
         self.win_starty = (self.maxy - self.win_height) / 2
         self.win_startx = (self.maxx - self.win_width) / 2
 
         self.menu_starty = self.win_starty + 3
 
5d05cfcc
         self.load_package_list(options_file)
f4d17450
 
         self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Select Installation', True, self.package_menu)
 
bbb09faa
     @staticmethod
2cbd5a80
     def get_packages_to_install(options, config_type, output_data_path):
bb884b5b
         package_list = []
         for install_option in options:
b94a5dc5
             if install_option[0] == config_type:
168bbfed
                 for include_type in install_option[1]["include"]:
                     package_list = package_list + PackageSelector.get_packages_to_install(options, include_type, output_data_path)
2cbd5a80
                 json_wrapper_package_list = JsonWrapper(os.path.join(output_data_path, install_option[1]["file"]))
bb884b5b
                 package_list_json = json_wrapper_package_list.read()
                 package_list = package_list + package_list_json["packages"]
                 break
         return package_list
 
2f46569e
     @staticmethod
     def get_additional_files_to_copy_in_iso(options, base_path, config_type):
         additional_files = []
         for install_option in options:
             if install_option[0] == config_type:
                 if install_option[1].has_key("additional-files"):
                     additional_files = install_option[1]["additional-files"]
                 break
         return additional_files
 
5d05cfcc
     def load_package_list(self, options_file):
         json_wrapper_option_list = JsonWrapper(options_file)
4d6a578d
         option_list_json = json_wrapper_option_list.read()
dc0dfc30
         options_sorted = option_list_json.items()
4d6a578d
 
         self.package_menu_items = []
bb884b5b
         base_path = os.path.dirname(options_file)
         package_list = []
4d6a578d
 
8d282b99
         default_selected = 0
         visible_options_cnt = 0
4d6a578d
         for install_option in options_sorted:
             if install_option[1]["visible"] == True:
2cbd5a80
                 package_list = PackageSelector.get_packages_to_install(options_sorted, install_option[0], base_path)
2f46569e
                 additional_files = PackageSelector.get_additional_files_to_copy_in_iso(options_sorted, base_path, install_option[0])
                 self.package_menu_items.append((install_option[1]["title"], self.exit_function, [install_option[0], package_list, additional_files] ))
8d282b99
                 if install_option[0] == 'minimal':
                     default_selected = visible_options_cnt
                 visible_options_cnt = visible_options_cnt + 1
4d6a578d
 
8d282b99
 
         self.package_menu = Menu(self.menu_starty,  self.maxx, self.package_menu_items, default_selected = default_selected)
f4d17450
 
     def exit_function(self,  selected_item_params):
         self.install_config['type'] = selected_item_params[0];
         self.install_config['packages'] = selected_item_params[1];
2f46569e
         self.install_config['additional-files'] = selected_item_params[2]
f4d17450
         return ActionResult(True, {'custom': False})
 
     def custom_packages(self, params):
         return ActionResult(True, {'custom': True})
 
     def display(self, params):
         return self.window.do_action()