Package backend :: Package server :: Package importlib :: Module kickstartImport
[hide private]
[frames] | no frames]

Source Code for Module backend.server.importlib.kickstartImport

 1  # 
 2  # Copyright (c) 2008--2015 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  # Package import process 
17  # 
18   
19  from importLib import KickstartableTree, Import 
20   
21   
22 -class KickstartableTreeImport(Import):
23
24 - def __init__(self, batch, backend):
25 Import.__init__(self, batch, backend) 26 27 self.channels = {} 28 29 self.kstree_types = {} 30 self.ks_install_types = {} 31 self.checksums = {}
32
33 - def preprocess(self):
34 # Processes the batch to a form more suitable for database 35 # operations 36 for ent in self.batch: 37 if not isinstance(ent, KickstartableTree): 38 raise TypeError("Expected a KickstartableTree instance") 39 40 channel_label = ent['channel'] 41 self.channels[channel_label] = None 42 43 # If the ks type and install type are missing, populate them 44 kstree_type_label = ent['kstree_type_label'] 45 kstree_type_name = ent['kstree_type_name'] 46 self.kstree_types[kstree_type_label] = kstree_type_name 47 48 ks_install_label = ent['install_type_label'] 49 ks_install_name = ent['install_type_name'] 50 self.ks_install_types[ks_install_label] = ks_install_name 51 for f in ent['files']: 52 checksumTuple = (f['checksum_type'], f['checksum']) 53 if checksumTuple not in self.checksums: 54 self.checksums[checksumTuple] = None
55
56 - def fix(self):
57 self.backend.lookup_kstree_types(self.kstree_types) 58 self.backend.lookup_ks_install_types(self.ks_install_types) 59 self.backend.lookupChannels(self.channels) 60 self.backend.lookupChecksums(self.checksums) 61 62 for ent in self.batch: 63 if ent.ignored: 64 continue 65 channel_label = ent['channel'] 66 channel = self.channels[channel_label] 67 if channel is None: 68 raise Exception("Channel %s not imported" % channel_label) 69 ent['channel_id'] = channel['id'] 70 # Now fix the other ids 71 kstree_type_label = ent['kstree_type_label'] 72 ks_install_label = ent['install_type_label'] 73 ent['kstree_type'] = self.kstree_types[kstree_type_label] 74 ent['install_type'] = self.ks_install_types[ks_install_label] 75 for f in ent['files']: 76 f['checksum_id'] = self.checksums[(f['checksum_type'], f['checksum'])]
77
78 - def submit(self):
79 self.backend.processKickstartTrees(self.batch) 80 self.backend.commit()
81