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

Source Code for Module backend.server.importlib.contentSourcesImport

 1  # 
 2  # Copyright (c) 2016--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   
17  from importLib import Import, Channel 
18  from spacewalk.server.rhnChannel import channel_info 
19   
20   
21 -class ContentSourcesImport(Import):
22
23 - def __init__(self, batch, backend):
24 Import.__init__(self, batch, backend) 25 self.channels_to_link = {}
26
27 - def preprocess(self):
28 for content_source in self.batch: 29 # Link back content sources to channel objects to subscribe them to existing channels right after import 30 if 'channels' in content_source and content_source['channels'] is not None: 31 for channel_label in content_source['channels']: 32 if channel_label not in self.channels_to_link: 33 db_channel = channel_info(channel_label) 34 channel_obj = Channel() 35 channel_obj.id = db_channel['id'] 36 channel_obj['content-sources'] = [] 37 self.channels_to_link[channel_label] = channel_obj 38 self.channels_to_link[channel_label]['content-sources'].append(content_source)
39
40 - def fix(self):
41 pass
42
43 - def submit(self):
44 try: 45 self.backend.processContentSources(self.batch) 46 for channel in self.channels_to_link.values(): 47 self.backend.processChannelContentSources(channel) 48 except: 49 self.backend.rollback() 50 raise 51 self.backend.commit()
52