def process(self): try: pid = Instrument.__getClasses()[self.classID] instrumentClass = FedoraWrapper.client.getObject(pid) except KeyError: instrumentClass = FedoraWrapper.getNextObject(self.prefix, label='Instrument class %s' % self.classID) Instrument.__addInstrumentClass(self.classID, instrumentClass.pid) c_rels = [ ( FR.rels_predicate(alias='fjm-db', predicate='instrumentClassID'), FR.rels_object(self.classID, FR.rels_object.LITERAL) ), ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:instrumentClassCModel', FR.rels_object.PID) ) ] FedoraWrapper.addRelationshipsWithoutDup(c_rels, fedora=instrumentClass).update() dc = dict() dc['title'] = [self.instrumentClass] Instrument.save_dc(instrumentClass, dc) instrumentClass.state = unicode('A') try: pid = Instrument.__getInstruments()[self.instrumentName] instrument = FedoraWrapper.client.getObject(pid) except KeyError: instrument = FedoraWrapper.getNextObject(self.prefix, label='Instrument %s' % self.dbid) Instrument.__addInstrument(self.instrumentName, instrument.pid) dc = dict() dc['title'] = [self.instrumentName] Instrument.save_dc(instrument, dc) i_rels = [ ( FR.rels_predicate(alias='fjm-db', predicate='instrumentID'), FR.rels_object(self.dbid, FR.rels_object.LITERAL) ), ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:instrumentCModel', FR.rels_object.PID) ), ( FR.rels_predicate(alias='fedora-rels-ext', predicate='isMemberOf'), FR.rels_object(instrumentClass.pid, FR.rels_object.PID) ) ] FedoraWrapper.addRelationshipsWithoutDup(i_rels, fedora=instrument).update() FedoraWrapper.correlateDBEntry('instrument', 'instrumentID') instrument.state = unicode('A')
def __processImage(self, el, firstImage): i_dict = { 'id': el.get('id', default=None), 'path': el.findtext('ruta'), 'description': el.findtext('pie'), 'line': el.sourceline } if i_dict['id'] and i_dict['path'] and path.exists(self.getPath(i_dict['path'])): #Get or create an new image containing the new object. try: image = FedoraWrapper.client.getObject(FedoraWrapper.getPid(uri=ao.NS['fjm-db'].uri, predicate='imageID', obj="'%(id)s'" % i_dict)) except KeyError: image = FedoraWrapper.getNextObject(self.prefix, label='Image: %(id)s' % i_dict) #FIXME: Detect Mimetype, and create image accordingly? update_datastream(obj=image, dsid="JPG", filename=self.getPath(i_dict['path']), mimeType="image/jpeg") i_rels_ext = FR.rels_ext(obj=image, namespaces=ao.NS.values()) rels = [ ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:imageCModel', FR.rels_object.PID) ), ( FR.rels_predicate(alias='fjm-db', predicate='imageID'), FR.rels_object(el.get('id'), FR.rels_object.LITERAL) ), #Relate the image to the concert as a general image... ( FR.rels_predicate(alias='atm-rel', predicate='isImageOf'), FR.rels_object(self.concert_obj.pid, FR.rels_object.PID) ) ] #Set the first image as the "primary" (Used for thumbnails) if firstImage: rels.append( ( FR.rels_predicate(alias='atm-rel', predicate='isIconOf'), FR.rels_object(self.concert_obj.pid, FR.rels_object.PID) ) ) #Update and commit the rels_ext FedoraWrapper.addRelationshipsWithoutDup(rels, rels_ext=i_rels_ext).update() dc = dict() dc['type'] = [unicode('StillImage')] #Add a description, based on the 'pie' (if it exists, and there isn't already on for the image...), and don't clobber any existing description... if i_dict['description'] and 'description' not in dc: dc['description'] = [unicode('%(description)s' % i_dict)] Concert.save_dc(image, dc) image.state = unicode('A') return True else: logger.warning('No ID or invalid path for image at line: %(line)s' % i_dict) return False
def process(self): logger = self.logger logger.info('Starting to ingest: %(class)s %(id)s' % {'class': type(self), 'id': self.dbid}) try: logger.info('Checking to see if %s already exists in Fedora' % self.norm_name) pid = self[self.norm_name] logger.info('Found %(pid)s' % {'pid': pid}) if pid: logger.warning('%(name)s already exists as pid %(pid)s! Overwriting DC DS!' % {'name': self.norm_name, 'pid': pid}) self.composer = FedoraWrapper.client.getObject(pid) else: msg = 'Something went horribly wrong! Found a pid (%(pid)s), but couldn\'t access it...' % {'pid': pid} logger.error(msg) raise Exception(msg) except KeyError: try: logger.debug('Not known by name, checking by composerID') pid = FedoraWrapper.getPid(uri=Composer.NS['fjm-db'].uri, predicate='composerID', obj="'%s'" % self.dbid) logger.info('Found %(pid)s' % {'pid': pid}) if pid: logger.warning('%(name)s already exists as pid %(pid)s! Overwriting DC DS!' % {'name': self.norm_name, 'pid': pid}) self.composer = FedoraWrapper.client.getObject(pid) else: msg = 'Something went horribly wrong! Found a pid (%(pid)s), but couldn\'t access it...' % {'pid': pid} logger.error(msg) raise Exception(msg) except KeyError: logger.info('Doesn\'t exist: creating a new Fedora Object') self.composer = FedoraWrapper.getNextObject(self.prefix, label='Composer %s' % self.dbid) rels_ext = FR.rels_ext(self.composer, namespaces=Composer.NS.values()) rels = [ ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:personCModel', FR.rels_object.PID) ), ( FR.rels_predicate(alias='fjm-db', predicate='composerID'), FR.rels_object(self.dbid, FR.rels_object.LITERAL) ) ] FedoraWrapper.addRelationshipsWithoutDup(rels, rels_ext=rels_ext).update() FedoraWrapper.correlateDBEntry('composedBy', 'composerID') #Yay Pythonic-ness? Try to get an existing EAC-CPF, or create one if none is found try: eaccpf = CPF.EACCPF(self.composer.pid, xml=self.composer['EAC-CPF'].getContent().read()) event_type="modified" except fcrepo.connection.FedoraConnectionException, e: if e.httpcode == 404: eaccpf = CPF.EACCPF(self.composer.pid) event_type="created" else: raise e
def __processConferences(self): logger = logging.getLogger('ingest.atm_concert.__processConferences') for el in self.element.findall('Eventos_Asociados/Evento_Asociado'): e_dict = { 'id': el.get('id'), 'type': el.findtext('Tipo'), 'description': el.findtext('descripcion'), 'mp3_path': el.findtext('ruta'), 'concert': self.dbid, 'line': el.sourceline } if e_dict['id']: try: pid = FedoraWrapper.getPid(uri=Concert.NS['fjm-db'].uri, predicate="lectureID", obj="'%(id)s'" % e_dict) conference = FedoraWrapper.client.getObject(pid) except KeyError: conference = FedoraWrapper.getNextObject(self.prefix, label="Conference %(id)s in %(concert)s" % e_dict) c_rels_ext = FR.rels_ext(obj=conference, namespaces=ao.NS.values()) rels = [ ( FR.rels_predicate(alias='fedora-rels-ext', predicate='isMemberOf'), FR.rels_object(self.concert_obj.pid, FR.rels_object.PID) ), ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:lectureCModel', FR.rels_object.PID) ), ( FR.rels_predicate(alias='fjm-db', predicate='lectureID'), FR.rels_object(e_dict['id'], FR.rels_object.LITERAL) ) ] #Add and commit relationships FedoraWrapper.addRelationshipsWithoutDup(rels, rels_ext=c_rels_ext).update() if e_dict['mp3_path']: mp3_path = self.getPath(e_dict['mp3_path']) if path.exists(mp3_path): update_datastream(obj=conference, dsid='MP3', filename=mp3_path, mimeType="audio/mpeg") else: logger.error('MP3 specified (%(mp3_path)s), but doesn\'t exist for id %(id)s on line %(line)s' % e_dict) else: logger.warning('No MP3 indicated for id %(id)s on line %(line)s' % e_dict) dc = dict() dc['type'] = [unicode('Sound')] dc['description'] = [unicode(e_dict['description'])] dc['subject'] = [unicode(e_dict['type'])] Concert.save_dc(conference, dc) conference.state = unicode('A')
def process(self): logger = self.logger logger.info('Starting to ingest: Groupo %s' % self.dbid) try: pid = FedoraWrapper.getPid(uri=ao.NS['fjm-db'].uri, predicate='groupID', obj="'%s'" % self.dbid) if pid: logger.warning('Group %(id)s already exists as pid %(pid)s! Overwriting DC DS!' % {'id': self.dbid, 'pid': pid}) group = FedoraWrapper.client.getObject(pid) else: raise Exception('Something went horribly wrong! Found a pid, but couldn\'t access it...') except KeyError: group = FedoraWrapper.getNextObject(self.prefix, label='Group %s' % self.dbid) rels_ext = FR.rels_ext(group, namespaces=ao.NS.values()) rels = [ ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:groupCModel', FR.rels_object.PID) ), ( FR.rels_predicate(alias='fjm-db', predicate='groupID'), FR.rels_object(self.dbid, FR.rels_object.LITERAL) ) ] FedoraWrapper.addRelationshipsWithoutDup(rels, rels_ext=rels_ext).update() dc = dict() dc['type'] = [unicode('Collection')] dc['title'] = [self.element.findtext('grupo').strip()] Group.save_dc(group, dc) FedoraWrapper.correlateDBEntry('group', 'groupID') group.state = unicode('A')
def process(self): logger = self.logger logger.info('Starting to ingest: Score %s' % self.dbid) try: pid = FedoraWrapper.getPid(uri=ao.NS['fjm-db'].uri, predicate='scoreID', obj="'%s'" % self.dbid) if pid: logger.warning('Score %(id)s already exists as pid %(pid)s! Overwriting PDF and DC DSs!' % {'id': self.dbid, 'pid': pid}) score = FedoraWrapper.client.getObject(pid) else: raise Exception('Something went horribly wrong! Found a pid, but couldn\'t access it...') except KeyError: score = FedoraWrapper.getNextObject(self.prefix, label='Score %s' % self.dbid) rels_ext = FR.rels_ext(score, namespaces=ao.NS.values()) rels = [ ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:scoreCModel', FR.rels_object.PID) ), ( FR.rels_predicate(alias='fjm-db', predicate='scoreID'), FR.rels_object(self.dbid, FR.rels_object.LITERAL) ) ] titn = self.element.findtext('titn_partitura') if titn: rels.append( ( FR.rels_predicate(alias='fjm-titn', predicate='score'), FR.rels_object(titn, FR.rels_object.LITERAL) ) ) #FIXME: 'Direction' of composer relation... Should I go from the score to the composer, or (as I think I do in my hand-made objects) from the composer to the score... Or should I make the relationships go in both directions? composer = self.element.findtext('ID_COMPOSITOR') if composer: rels.append( ( FR.rels_predicate(alias='fjm-db', predicate='composedBy'), FR.rels_object(composer, FR.rels_object.LITERAL) ) ) FedoraWrapper.addRelationshipsWithoutDup(rels, rels_ext=rels_ext).update() FedoraWrapper.correlateDBEntry('composedBy', 'composerID') FedoraWrapper.correlateDBEntry('basedOn', 'scoreID') dc = dict() dc['type'] = [unicode('StillImage')] dc['title'] = [self.element.findtext('TITULO')] Score.save_dc(score, dc) filename = self.element.findtext('Ruta_Partitura') if filename: fn = self.getPath(filename) if path.exists(fn): update_datastream(obj=score, dsid='PDF', label="Score PDF", filename=fn, mimeType='application/pdf') else: logger.error('PDF specified for score %(id)s, but file does not seem to exist!' % {'id': self.dbid}) marc = self.getPath(path.join(path.dirname(filename), '%s.xml' % self.dbid)) if path.exists(marc): update_datastream(obj=score, dsid='MARCXML', label="MARC XML", filename=marc, mimeType='application/xml') else: logger.info('No PDF for %s', self.dbid)
def process(self): #self.logger.debug('Received line: %s' % self.element) info = dict() for part, value in zip(['forename', 'surname', 'birth_date', 'death_date', 'alt_forename', 'ceacs_member', 'academic_page', 'ceacs_arrival', 'ceacs_depart', 'phd_date', 'photo'], self.element): val = unicode(value.strip(), 'UTF-8', 'replace') if val or part in ['birth_date', 'death_date']: info[part] = val if 'photo' not in info: return #self.logger.debug('info dictionary: %s' % info) info['full_name'] = "%(surname)s, %(forename)s" % info auth_record = FedoraWrapper.getNextObject(prefix=self.prefix, label=info['full_name'].encode('ascii', 'replace')) cpf = eaccpf(auth_record.pid) cpf.add_maintenance_event(agent="Adam Vessey, via ir_authority.py") cpf.add_bin_source(caption='Row in Excel spreadsheet', obj=str(self.element)) cpf.add_name_entry(name={ 'forename': info['forename'], 'surname': info['surname'] }) if 'alt_forename' in info: cpf.add_name_entry(name={ 'forename': info['alt_forename'], 'surname': info['surname'] }, role='alternative') cl = list() rel = list() if 'phd_date' in info: cl.append({ 'date': info['phd_date'], 'event': 'Achieved PhD' }) if 'ceacs_arrival' in info and 'ceacs_depart' in info: rel = { 'dateRange': { 'fromDate': info['ceacs_arrival'], 'toDate': info['ceacs_depart'] }, 'event': 'CEACS membership' } elif 'ceacs_arrival' in info: rel = { 'dateRange': { 'fromDate': info['ceacs_arrival'] }, 'event': 'CEACS membership' } elif 'ceacs_depart' in info: rel = { 'dateRange': { 'toDate': info['ceacs_depart'] }, 'event': 'CEACS membership' } if cl: cpf.add_chron_list(cl) if rel: cpf.add_relation(type='cpfRelation', url='http://digital.march.es/ceacs', elements=rel) if 'academic_page' in info: cpf.add_relation(type="resourceRelation", url=info['academic_page'], elements={'descriptiveNote': 'Academic page'}) cpf.add_exist_dates(info['birth_date'], info['death_date']) #print(cpf) Authority.save_etree(auth_record, cpf.element, 'EAC-CPF', 'EAC-CPF record', controlGroup='X', hash='DISABLED') rels = FR.rels_ext(obj=auth_record, namespaces=Authority.NS.values()) rels.addRelationship(['fedora-model', 'hasModel'], ['ir:authorityCModel', 'pid']) rels.update() #Add image (with relationship to object?). if 'photo' in info: photo_path = self.getPath(info['photo']) if path.exists(photo_path): #Create the object... photo = FedoraWrapper.getNextObject(self.prefix, label=('Photo of %s' % info['full_name']).encode('ascii', 'replace')) #... add the datastream ... update_datastream(photo, 'JPG', filename=photo_path, label='Original image', checksumType='SHA-1', mimeType='image/jpeg') #... and relate the object. NSs = Authority.NS NSs['ir-rel'] = FR.rels_namespace('ir-rel', 'http://digital.march.es/ceacs#') p_rels = FR.rels_ext(photo, namespaces=NSs.values()) p_rels.addRelationship(['fedora-model', 'hasModel'], ['ir:photoCModel', 'pid']) p_rels.addRelationship(['ir-rel', 'iconOf'], [auth_record.pid, 'pid']) p_rels.update() else: self.logger.warning('photo: %s specified, but %s does not exist!' % (info['photo'], photo_path)) else: self.logger.debug('No photo specified.')
def process(self): logger = self.logger logger.info('Starting to ingest: Performer %s' % self.dbid) try: logger.info('Checking to see if %s already exists in Fedora' % self.norm_name) pid = self[self.norm_name] logger.info('Found %(pid)s' % {'pid': pid}) if pid: logger.warning('%(name)s already exists as pid %(pid)s!' % {'name': self.norm_name, 'pid': pid}) self.performer = FedoraWrapper.client.getObject(pid) else: msg = 'Something went horribly wrong! Found a pid (%(pid)s), but couldn\'t access it...' % {'pid': pid} logger.error(msg) raise Exception(msg) except KeyError: try: logger.debug('Not known by name, checking by performerID') pid = FedoraWrapper.getPid(uri=Performer.NS['fjm-db'].uri, predicate='performerID', obj="'%s'" % self.dbid) logger.info('Found %(pid)s' % {'pid': pid}) if pid: logger.warning('%(name)s already exists as pid %(pid)s! Overwriting DC DS!' % {'name': self.norm_name, 'pid': pid}) self.performer = FedoraWrapper.client.getObject(pid) else: msg = 'Something went horribly wrong! Found a pid (%(pid)s), but couldn\'t access it...' % {'pid': pid} logger.error(msg) raise Exception(msg) except KeyError: logger.info('Doesn\'t exist: creating a new Fedora Object') self.performer = FedoraWrapper.getNextObject(self.prefix, label='Performer: %s' % self.dbid) dc = dict() dc['title'] = [self.norm_name] Performer.save_dc(self.performer, dc) rels_ext = FR.rels_ext(self.performer, namespaces=Performer.NS.values()) rels = [ ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:personCModel', FR.rels_object.PID) ), ( FR.rels_predicate(alias='fjm-db', predicate='performerID'), FR.rels_object(self.dbid, FR.rels_object.LITERAL) ) ] FedoraWrapper.addRelationshipsWithoutDup(rels, rels_ext=rels_ext).update() #Yay Pythonic-ness? Try to get an existing EAC-CPF, or create one if none is found try: eaccpf = CPF.EACCPF(self.performer.pid, xml=self.performer['EAC-CPF'].getContent().read()) event_type="modified" except fcrepo.connection.FedoraConnectionException as e: if e.httpcode == 404: eaccpf = CPF.EACCPF(self.performer.pid) event_type="created" else: raise e eaccpf.add_maintenance_event(type=event_type, time="now", agent_type="machine", agent="atm_performer.py") eaccpf.add_XML_source(caption='XML from database dump', xml=self.element) eaccpf.add_name_entry(name=self.name) Performer.save_etree(self.performer, eaccpf.element, 'EAC-CPF', 'EAC-CPF record', controlGroup='M') self[self.norm_name] = self.performer.pid self.performer.state = unicode('A') FedoraWrapper.correlateDBEntry('player', 'performerID')
def __processConcert(self): logger = logging.getLogger('ingest.atm_concert.Concert.__processConcert') #Get the/an object try: pid = FedoraWrapper.getPid(uri=Concert.NS['fjm-db'].uri, predicate='concertID', obj="'%s'" % self.dbid) if pid: logger.warning('Concert %s found as %s. Overwriting DSs!' % (self.dbid, pid)) concert = FedoraWrapper.client.getObject(pid) except KeyError: concert = FedoraWrapper.getNextObject(prefix=self.prefix, label="concert %s" % self.dbid) logger.info('Adding CustomXML datastream') if Concert.save_etree(concert, self.element, 'CustomXML', 'Original XML', controlGroup='M'): logger.info('CustomXML added successfully') else: logger.error('Error while adding CustomXML!') #Ingest the WAV (if it exists...) WAV = self.element.findtext('Grabacion/wav') if WAV: WAV = self.getPath(WAV) if path.exists(WAV): update_datastream(obj=concert, dsid='WAV', filename=WAV, label='WAV', mimeType="audio/x-wav") else: logger.warning('WAV file specified (%s), but does not exist!', WAV) else: logger.warning('No WAV found at %s! Skipping...', WAV) #Ingest the MARCXML... FIXME: Maybe this might not make sense to attempt, if there's no WAV? MARC = path.join(path.dirname(WAV), '%s.xml' % self.dbid) if path.exists(MARC): update_datastream(obj=concert, dsid='MARCXML', mimeType="application/xml", filename=MARC) logger.debug('Added %s', MARC) else: logger.debug('Couldn\'t find MARCXML at %s', MARC) cycle_info = { 'norm_name': Concert.normalize_name([self.element.findtext('tipo')]) } #Create cycle stuff try: pid = Concert.__cycles()[cycle_info['norm_name']] cycle = FedoraWrapper.client.getObject(pid) except KeyError: cycle = FedoraWrapper.getNextObject(prefix=self.prefix, label='Cycle %s' % (len(Concert.__cycles()) + 1)) Concert.__cycles()[cycle_info['norm_name']] = cycle.pid c_dc = dict() c_dc['title'] = [cycle_info['norm_name']] Concert.save_dc(cycle, c_dc) FedoraWrapper.addRelationshipsWithoutDup(rels=[ ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:concertCycleCModel', FR.rels_object.PID) ) ], fedora=cycle).update() #Add relations to concert object rels_ext = FR.rels_ext(obj=concert, namespaces=ao.NS.values()) rels = [ #Don't know that this one is necessary... Oh well... ( FR.rels_predicate(alias='fjm-db', predicate='concertID'), FR.rels_object(self.dbid, FR.rels_object.LITERAL) ), ( FR.rels_predicate(alias='fedora-rels-ext', predicate='isMemberOfCollection'), FR.rels_object('atm:concertCollection', FR.rels_object.PID) ), ( FR.rels_predicate(alias='fedora-rels-ext', predicate='isMemberOf'), FR.rels_object(cycle.pid, FR.rels_object.PID) ), ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:concertCModel', FR.rels_object.PID) ) ] #Write 'out' rels_ext FedoraWrapper.addRelationshipsWithoutDup(rels, rels_ext=rels_ext).update() desc = self.element.findtext('Descripcion') dc = dict() dc['type'] = [unicode('Event')] if desc: dc['description'] = [unicode(desc)] dc['title'] = [unicode(Concert.normalize_name([self.element.findtext('titulo')]))] Concert.save_dc(concert, dc) self.concert_obj = concert concert.state = unicode('A')
def __processPerformance(self, p_el): logger = logging.getLogger('ingest.atm_concert.Concert.__processPerformance') p_dict = { 'piece': p_el.get('id_obra'), 'concert': self.dbid, 'order': p_el.findtext('Posicion') } #TODO: Bloody well deduplicate (ensure that this object does not already exist in Fedora) try: pid = FedoraWrapper.getPid(tuples=[ (Concert.NS['fjm-db'].uri, 'basedOn', "'%s'" % p_dict['piece']), #Not sure if this is really necessary with the other two conditions... ('fedora-rels-ext:', 'isMemberOf', "<fedora:%s>" % self.concert_obj.pid), #To ensure that the performance actually belongs to this concert... (Concert.NS['atm-rel'].uri, 'concertOrder', "'%s'" % p_dict['order']) #To eliminate the confusion if the same piece is played twice in the same concert. ]) if pid: performance = FedoraWrapper.client.getObject(pid) except KeyError: performance = FedoraWrapper.getNextObject(self.prefix, label='Performance of %(piece)s in %(concert)s' % p_dict) #Add MP3 to performance (if there is one to add) p_mp3 = p_el.findtext('mp3_Obra') if p_mp3: mp3_path = self.getPath(p_mp3) if path.exists(mp3_path): update_datastream(obj=performance, dsid='MP3', filename=mp3_path, mimeType='audio/mpeg') else: logger.warning('MP3 entry for performance of %(piece)s in concert %(concert)s, but the file does not exist!' % p_dict) else: logger.debug('No performance MP3 for %(concert)s/%(piece)s' % p_dict) #Add relationships #1 - To concert #2 - To score #3 - To CM #4 - Position in concert rels_ext = FR.rels_ext(obj=performance, namespaces=ao.NS.values()) rels = [ ( FR.rels_predicate(alias='fedora-rels-ext', predicate='isMemberOf'), FR.rels_object(self.concert_obj.pid, FR.rels_object.PID) ), ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:performanceCModel', FR.rels_object.PID) ), ( FR.rels_predicate(alias='atm-rel', predicate='concertOrder'), FR.rels_object(p_dict['order'], FR.rels_object.LITERAL) ), ( FR.rels_predicate(alias='fjm-db', predicate='basedOn'), FR.rels_object(p_dict['piece'], FR.rels_object.LITERAL) ) ] #Add relations and commit FedoraWrapper.addRelationshipsWithoutDup(rels, rels_ext=rels_ext).update() FedoraWrapper.correlateDBEntry('basedOn', 'scoreID') #Create objects for any movements within the piece for m_el in p_el.findall('Movimientos/Movimiento'): m_dict = { 'concert': p_dict['concert'], 'piece': p_dict['piece'], 'id': m_el.get('id'), 'corder': p_dict['order'], 'porder': m_el.get('posicion'), 'name': m_el.findtext('NOMBRE'), 'MP3': m_el.findtext('mp3_Movimiento'), 'line': m_el.sourceline, 'file': self.file_name } #Sanity test if m_dict['porder']: #Get a Fedora Object for this movement try: pid = FedoraWrapper.getPid(tuples=[ ('fedora-rels-ext:', 'isMemberOf', '<fedora:%s>' % performance.pid), ('fedora-model:', 'hasModel', '<fedora:atm:movementCModel>'), (Concert.NS['atm-rel'].uri, 'pieceOrder', "'%s'" % m_dict['porder']) ]) mov = FedoraWrapper.client.getObject(pid) except KeyError: mov = FedoraWrapper.getNextObject(self.prefix, label='Movement: %(concert)s/%(piece)s/%(id)s' % m_dict) #Get DC and set the title if we have a name. mov_dc = dict() mov_dc['type'] = [unicode('Event')] if m_dict['name']: mov_dc['title'] = [unicode(m_dict['name'])] Concert.save_dc(mov, mov_dc) #Set the three required relations: #1 - To the performance #2 - To the content model #3 - The order this movement occurs within the piece m_rels_ext = FR.rels_ext(obj=mov, namespaces=Concert.NS.values()) m_rels = [ ( FR.rels_predicate(alias='fedora-rels-ext', predicate='isMemberOf'), FR.rels_object(performance.pid, FR.rels_object.PID) ), ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:movementCModel', FR.rels_object.PID) ), ( FR.rels_predicate(alias='atm-rel', predicate='pieceOrder'), FR.rels_object(m_dict['porder'], FR.rels_object.LITERAL) ) ] FedoraWrapper.addRelationshipsWithoutDup(m_rels, rels_ext=m_rels_ext).update() #Add the MP3 (if it exists) if m_dict['MP3']: mp3_path = self.getPath(m_dict['MP3']) if path.exists(mp3_path): update_datastream(obj=mov, dsid='MP3', filename=mp3_path, mimeType='audio/mpeg') else: logger.warning("MP3 entry for movement %(id)s in performance of %(piece)s in %(concert)s on line %(line)s of %(file)s" % m_dict) else: logger.debug('No movement MP3 for %(concert)s/%(piece)s/%(id)s on line %(line)s of %(file)s' % m_dict) else: logger.error('Movement %(concert)s/%(piece)s/%(id)s does not have a position near line %(line)s of %(file)s!' % m_dict) #Done with movements #Create objects for the performers. for per_el in p_el.findall('Interpretes/Interprete'): perf = { 'id': per_el.get('id'), 'group': per_el.get('id_grupo', default=None), 'line': per_el.sourceline, 'file': self.file_name } perf.update(p_dict) if perf['id']: rels = [ #Relate performer to CModel ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:performerCModel', FR.rels_object.PID) ), #Relate performer to performance ( FR.rels_predicate(alias='atm-rel', predicate='performance'), FR.rels_object(performance.pid, FR.rels_object.PID) ), #Relate perfomer to their 'person' entry ( FR.rels_predicate(alias='fjm-db', predicate='player'), FR.rels_object(perf['id'], FR.rels_object.LITERAL) ) ] try: t_list = list() for pred, obj in rels: if obj.type == FR.rels_object.LITERAL: t_obj = "'%s'" % obj else: t_obj = "<fedora:%s>" % obj t_list.append(("%s" % Concert.NS[pred.alias].uri, "%s" % pred.predicate, "%s" % t_obj)) pid = FedoraWrapper.getPid(tuples=t_list) if pid: performer = FedoraWrapper.client.getObject(pid) except KeyError: performer = FedoraWrapper.getNextObject(prefix = self.prefix, label = 'Performer: %(concert)s/%(piece)s/%(id)s in group %(group)s' % perf) #Relate the performer to the listed group (or 'unaffiliated, if none) if perf['group'] != None: rels.append( ( FR.rels_predicate(alias='fjm-db', predicate='group'), FR.rels_object(perf['group'], FR.rels_object.LITERAL) ) ) else: rels.append( ( FR.rels_predicate(alias='atm-rel', predicate='group'), FR.rels_object('atm:unaffiliatedPerfomer', FR.rels_object.PID) ) ) for i_el in per_el.findall('Instrumentos/Instrumento'): inst_id = i_el.get('id') rels.append( ( FR.rels_predicate(alias='fjm-db', predicate='instrument'), FR.rels_object(inst_id, FR.rels_object.LITERAL) ) ) FedoraWrapper.addRelationshipsWithoutDup(rels, fedora=performer).update() FedoraWrapper.correlateDBEntry('player', 'performerID') FedoraWrapper.correlateDBEntry('group', 'groupID') FedoraWrapper.correlateDBEntry('instrument', 'instrumentID') else: logger.error("Performer on line %(line)s of %(file)s does not have an ID!" % perf)
def __processProgram(self): p_el = self.element.find('programa') filename = self.getPath(p_el.findtext('ruta')) if len(p_el) != 0: try: pid = FedoraWrapper.getPid(uri=Concert.NS['fjm-db'].uri, predicate='programConcertID', obj="'%s'" % self.dbid) program = FedoraWrapper.client.getObject(pid) except KeyError: #Get a Fedora Object for the program program = FedoraWrapper.getNextObject(self.prefix, label='Program for concert %(dbid)s' % {'dbid': self.dbid}) #Add the PDF to the program object... Should probably do an "existence" check, but anyway... update_datastream(obj=program, dsid='PDF', filename=filename, mimeType='application/pdf' ) #Create the RELS-EXT datastream rels_ext = FR.rels_ext(obj=program, namespaces=ao.NS.values()) rels = [ ( FR.rels_predicate(alias='fedora-rels-ext', predicate='isMemberOf'), FR.rels_object(self.concert_obj.pid, FR.rels_object.PID) ), ( FR.rels_predicate(alias='fedora-model', predicate='hasModel'), FR.rels_object('atm:programCModel', FR.rels_object.PID) ), ( FR.rels_predicate(alias='fjm-db', predicate='programConcertID'), FR.rels_object(self.dbid, FR.rels_object.LITERAL) ) ] for a_el in p_el.findall('AutorNotas[@id]'): fore, sur = a_el.findtext('Nombre'), a_el.findtext('Apellidos') normed = self.normalize_name([fore, sur]) try: pid = Person._people()[normed] author = FedoraWrapper.client.getObject(pid) except KeyError: author = FedoraWrapper.getNextObject(self.prefix, label="an author") dc = dict() dc['title'] = [normed] Concert.save_dc(author, dc) rels.append( ( FR.rels_predicate(alias='atm-rel', predicate='authoredBy'), FR.rels_object(author.pid, FR.rels_object.PID) ) ) FedoraWrapper.addRelationshipsWithoutDup([ ( FR.rels_predicate(alias='fedora-model', predicate="hasModel"), FR.rels_object('atm:personCModel', FR.rels_object.PID) ) ], fedora=author).update() #Yay Pythonic-ness? Try to get an existing EAC-CPF, or create one if none is found try: #No point in updating if there's already one there... This is really just a check? eaccpf = CPF.EACCPF(author.pid, xml=author['EAC-CPF'].getContent().read()) event_type="modified" except fcrepo.connection.FedoraConnectionException, e: if e.httpcode == 404: eaccpf = CPF.EACCPF(author.pid) event_type="created" else: raise e eaccpf.add_maintenance_event(type=event_type, time="now", agent_type="machine", agent="atm_concert.py") eaccpf.add_XML_source(caption='(Slightly modified (Put into an element)) XML from database dump', xml=a_el) eaccpf.add_name_entry(name={'forename': fore, 'surname': sur}) Concert.save_etree(author, eaccpf.element, 'EAC-CPF', 'EAC-CPF record', controlGroup='M') author.state = unicode('A') #XXX: This is seeming particularly less-than-elegant at the moment, creating a 'placeholder' object for composer notes... Anyway. if len(p_el.findall('Notas_Obras/Obra[@id]')) > 0: try: pid = '%s:composerText' % self.prefix author = FedoraWrapper.client.getObject(pid) except: author = FedoraWrapper.client.createObject(pid, label=unicode('Composer Text')) #Yay Pythonic-ness? Try to get an existing EAC-CPF, or create one if none is found try: eaccpf = CPF.EACCPF(author.pid, xml=author['EAC-CPF'].getContent().read()) event_type="modified" except fcrepo.connection.FedoraConnectionException, e: if e.httpcode == 404: eaccpf = CPF.EACCPF(author.pid) event_type="created" else: raise e eaccpf.add_maintenance_event(type=event_type, time="now", agent_type="machine", agent="atm_concert.py") name = {'forename': 'Texto', 'surname': 'Compositores'} eaccpf.add_name_entry(name=name) dc = dict() dc['title'] = Concert.normalize_name(name) Concert.save_dc(author, dc) Concert.save_etree(author, eaccpf.element, 'EAC-CPF', 'EAC-CPF record', controlGroup='M') rels.append( ( FR.rels_predicate(alias='atm-rel', predicate='authoredBy'), FR.rels_object(author.pid, FR.rels_object.PID) ) ) author.state = unicode('A')