Package backend :: Package satellite_tools :: Package disk_dumper :: Module iss_actions
[hide private]
[frames] | no frames]

Source Code for Module backend.satellite_tools.disk_dumper.iss_actions

  1  # 
  2  # Copyright (c) 2008--2017 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   
 18  import iss_ui 
 19   
 20   
21 -class ActionDeps:
22
23 - def __init__(self, options):
24 # self.step_precedence contains the dependencies among the export steps. 25 self.step_precedence = { 26 'orgs': [''], 27 'packages': [''], 28 'source-packages': [''], 29 'errata': [''], 30 'kickstarts': [''], 31 'rpms': [''], 32 # 'srpms' : ['channels'], 33 'channels': ['channel-families'], 34 'channel-families': ['blacklists'], 35 'blacklists': ['arches'], 36 'short': ['channels'], 37 'arches': ['arches-extra'], 38 'arches-extra': [''], 39 'productnames': [''], 40 } 41 42 # self.step_hierarchy lists the export steps in the order they need to be run. 43 self.step_hierarchy = [ 44 'orgs', 45 'channel-families', 46 'arches', 47 'arches-extra', 48 'productnames', 49 'channels', 50 'blacklists', 51 'short', 52 'rpms', 53 'packages', 54 'errata', 55 'kickstarts', 56 ] 57 self.options = options 58 self.action_dict = {'blacklists': 0}
59
60 - def list_steps(self):
61 print("LIST OF STEPS:") 62 for step in self.step_hierarchy: 63 print(step) 64 sys.exit(0)
65 66 # Contains the logic for the --step option
67 - def handle_step_option(self):
68 # If the user didn't use --step, set the last step to the end of self.step_hierarchy. 69 if not self.options.step: 70 self.options.step = self.step_hierarchy[-1] 71 72 # Make sure that the step entered by the user is actually a step. 73 if self.options.step not in self.step_hierarchy: 74 sys.stderr.write("Error: '%s' is not a valid step.\n" % self.options.step) 75 sys.exit(-1) 76 77 # Turn on all of the steps up to the option set as self.options.step. 78 for step in self.step_hierarchy: 79 self.action_dict[step] = 1 80 if step == self.options.step: 81 break 82 83 # This will set the rest of the steps to 0. 84 for step in self.step_hierarchy: 85 self.action_dict[step] = step in self.action_dict
86 87 # Handles the logic for the --no-rpms, --no-packages, --no-errata, --no-kickstarts, and --list-channels.
88 - def handle_options(self):
89 90 if self.options.list_steps: 91 self.list_steps() 92 93 if self.options.no_rpms: 94 self.action_dict['rpms'] = 0 95 96 if self.options.no_packages: 97 self.action_dict['packages'] = 0 98 99 if self.options.no_errata: 100 self.action_dict['errata'] = 0 101 102 if self.options.no_kickstarts: 103 self.action_dict['kickstarts'] = 0 104 105 if not self.options.all_orgs and not self.options.org: 106 self.action_dict['orgs'] = 0 107 108 if self.options.list_channels: 109 self.action_dict['channels'] = 1 110 self.action_dict['blacklists'] = 0 111 self.action_dict['arches'] = 0 112 self.action_dict['channel-families'] = 1
113 114 # This method uses self.step_precendence to figure out if a step needs to be turned off.
115 - def turn_off_dep_steps(self, step):
116 for dependent in self.step_precedence[step]: 117 if dependent in self.action_dict: 118 self.action_dict[dependent] = 0
119 120 # This method will call turn_off_dep_steps if the step is off or not present in self.action_dict.
121 - def handle_step_dependents(self):
122 for step in self.step_hierarchy: 123 if step in self.action_dict: 124 if self.action_dict[step] == 0: 125 self.turn_off_dep_steps(step) 126 else: 127 self.turn_off_dep_steps(step)
128 129 # This will return the step_hierarchy and the action_dict.
130 - def get_actions(self):
131 self.handle_step_option() 132 self.handle_options() 133 self.handle_step_dependents() 134 return self.step_hierarchy, self.action_dict
135 136 if __name__ == "__main__": 137 a = iss_ui.UI() 138 b = ActionDeps(a) 139 print(b.get_actions()) 140