def import_channels(channels, orgid=None, master=None): collection = ChannelCollection() batch = [] import satCerts orgs = map(lambda a: a['id'], satCerts.get_all_orgs()) org_map = None my_backend = diskImportLib.get_backend() if master: org_map = my_backend.lookupOrgMap(master)['master-id-to-local-id'] for c in channels: try: timestamp = collection.get_channel_timestamp(c) except KeyError: raise Exception, "Could not find channel %s" % c, sys.exc_info()[2] c_obj = collection.get_channel(c, timestamp) if c_obj is None: raise Exception, "Channel not found in cache: %s" % c # Check to see if we're asked to sync to an orgid, # make sure the org from the export is not null org, # finally if the orgs differ so we might wanna use # requested org's channel-family. # TODO: Move these checks somewhere more appropriate if not orgid and c_obj['org_id'] is not None: #If the src org is not present default to org 1 orgid = DEFAULT_ORG if orgid is not None and c_obj['org_id'] is not None and \ c_obj['org_id'] != orgid: #If we know the master this is coming from and the master org #has been mapped to a local org, transform org_id to the local #org_id. Otherwise just put it in the default org. if (org_map and c_obj['org_id'] in org_map.keys() and org_map[c_obj['org_id']]): c_obj['org_id'] = org_map[c_obj['org_id']] else: c_obj['org_id'] = orgid if c_obj.has_key('trust_list'): del(c_obj['trust_list']) for family in c_obj['families']: family['label'] = 'private-channel-family-' + \ str(c_obj['org_id']) # If there's a trust list on the channel, transform the org ids to # the local ones if c_obj.has_key('trust_list') and c_obj['trust_list']: trusts = [] for trust in c_obj['trust_list']: if org_map.has_key(trust['org_trust_id']): trust['org_trust_id'] = org_map[trust['org_trust_id']] trusts.append(trust) c_obj['trust_list'] = trusts syncLib.log(6, "Syncing Channel %s to Org %s " % \ (c_obj['label'], c_obj['org_id'])) batch.append(c_obj) importer = channelImport.ChannelImport(batch, my_backend) # Don't commit just yet importer.will_commit = 0 importer.run() return importer
def import_channels(channels, orgid=None): collection = ChannelCollection() batch = [] import satCerts orgs = map(lambda a: a['id'], satCerts.get_all_orgs()) for c in channels: try: timestamp = collection.get_channel_timestamp(c) except KeyError: raise Exception, "Could not find channel %s" % c c_obj = collection.get_channel(c, timestamp) if c_obj is None: raise Exception, "Channel not found in cache: %s" % c # Check to see if we're asked to sync to an orgid, # make sure the org from the export is not null org, # finally if the orgs differ so we might wanna use # requested org's channel-family. # TODO: Move these checks somewhere more appropriate if not orgid and c_obj['org_id'] is not None: #If the src org is not present default to org 1 orgid = DEFAULT_ORG if orgid is not None and c_obj['org_id'] is not None and \ c_obj['org_id'] != orgid: #Only set the channel family if its a custom channel c_obj['org_id'] = orgid for family in c_obj['families']: family['label'] = 'private-channel-family-' + \ str(c_obj['org_id']) syncLib.log(6, "Syncing Channel %s to Org %s " % \ (c_obj['label'], c_obj['org_id'])) batch.append(c_obj) importer = channelImport.ChannelImport(batch, diskImportLib.get_backend()) # Don't commit just yet importer.will_commit = 0 importer.run() return importer