Package actions :: Module ModeControllerCreator
[hide private]
[frames] | no frames]

Source Code for Module actions.ModeControllerCreator

 1  # 
 2  # Copyright (c) 2008--2016 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
14  # 
15   
16  import sys 
17  import ModeController 
18  import Modes 
19   
20 -class ModeControllerCreator:
21 #if mode_list isn't set in the constructor, the populate_list is going to have to be called before create_controller.
22 - def __init__(self, mode_list=None):
23 self.mode_list = mode_list or [] 24 25 #A reference to a class obj. This is the type of controller that will be returned by create_controller. 26 self.controller_class = ModeController.ModeController
27 28 #Sets the class that the controller will be instantiated as. The constructor for the class shouldn't have 29 #to take any parameters.
30 - def set_controller_class(self, controller_class):
31 self.controller_class = controller_class
32 33 #Populates self.mode_list with concrete implementations of Modes.
34 - def populate_list(self, mode_list):
35 self.mode_list = mode_list
36 37 #using the Modes in self.mode_list, create, populate, and return a ModeController
38 - def create_controller(self):
39 controller = self.controller_class() 40 41 for m in self.mode_list: 42 controller.add_mode(m) 43 44 return controller
45
46 -def get_controller_creator():
47 if sys.platform.find('sunos') > -1: 48 mode_list = [Modes.SolarisDeployMode(), Modes.SolarisDiffMode(), Modes.SolarisUploadMode(), Modes.SolarisMTimeUploadMode(), Modes.SolarisAllMode()] 49 else: 50 mode_list = [Modes.DeployMode(), Modes.DiffMode(), Modes.UploadMode(), Modes.MTimeUploadMode(), Modes.AllMode()] 51 52 controller = ModeControllerCreator(mode_list=mode_list) 53 controller.set_controller_class(ModeController.ConfigFilesModeController) 54 return controller
55
56 -def get_run_controller_creator():
57 if sys.platform.find('sunos') > -1: 58 mode_list = [Modes.SolarisRunMode(), Modes.SolarisRunAllMode()] 59 else: 60 mode_list = [Modes.RunMode(), Modes.RunAllMode()] 61 62 controller = ModeControllerCreator(mode_list=mode_list) 63 return controller
64