installer/packageselector.py
f4d17450
 #
 #    Copyright (C) 2015 vmware inc.
 #
 #    Author: Mahmoud Bassiouny <mbassiouny@vmware.com>
 
5d05cfcc
 import os
f4d17450
 from jsonwrapper import JsonWrapper
 from menu import Menu
 from window import Window
 from actionresult import ActionResult
 
 class PackageSelector(object):
c533b308
     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
 
0c250142
         self.win_starty = (self.maxy - self.win_height) // 2
         self.win_startx = (self.maxx - self.win_width) // 2
f4d17450
 
         self.menu_starty = self.win_starty + 3
 
5d05cfcc
         self.load_package_list(options_file)
f4d17450
 
564d9533
         self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx,
c533b308
                              'Select Installation', True, action_panel=self.package_menu,
                              can_go_next=True, position=1)
f4d17450
 
bbb09faa
     @staticmethod
2cbd5a80
     def get_packages_to_install(options, config_type, output_data_path):
bb884b5b
         package_list = []
         for install_option in options:
fcc5e76b
             if install_option[0] == config_type:
168bbfed
                 for include_type in install_option[1]["include"]:
c533b308
                     package_list = (package_list +
                                     PackageSelector.get_packages_to_install(options,
                                                                             include_type,
                                                                             output_data_path))
                 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"]
c01f1bff
 
                 if "remove" in install_option[1]:
                     for package in install_option[1]["remove"]:
                         package_list.remove(package)
 
bb884b5b
                 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:
0c250142
                 if "additional-files" in install_option[1]:
2f46569e
                     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:
c533b308
                 package_list = PackageSelector.get_packages_to_install(options_sorted,
                                                                        install_option[0],
                                                                        base_path)
                 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
 
c533b308
         self.package_menu = Menu(self.menu_starty, self.maxx, self.package_menu_items,
                                  default_selected=default_selected, tab_enable=False)
f4d17450
 
c533b308
     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()