def submitMicalaMetadata(aw, IndicoID, contentType, LODBID, LOID, videoFormat, languages): '''Generate a lecture.xml file for the given event, then web upload it to the micala server.''' # Logger.get('RecMan').debug('in submitMicalaMetadata()') # Initialize success flag, and result string to which we will append any errors. flagSuccess = True result = "" # First update the micala database that we've started this task try: idMachine = MicalaCommunication.getIdMachine( CollaborationTools.getOptionValue("RecordingManager", "micalaDBMachineName")) idTask = MicalaCommunication.getIdTask( CollaborationTools.getOptionValue("RecordingManager", "micalaDBStatusExportMicala")) idLecture = LODBID # Logger.get('RecMan').debug('submitMicalaMetadata calling reportStatus...') MicalaCommunication.reportStatus('START', '', idMachine, idTask, idLecture) except Exception, e: flagSuccess = False result += _( "Unknown error occured when updating MICALA START task information in micala database: %s\n." ) % e
def _getAnswer(self): """This method does everything necessary to create a CDS record and also update the micala database. For plain_video talks, it does the following: - calls createCDSRecord(), which generates the MARC XML, submits it to CDS, and makes sure a record for this talk exists in micala DB For web_lecture talks, it does the following: - calls createCDSRecord(), which generates the MARC XML and submits it to CDS - calls associateIndicoIDToLOID(), which associates the chosen IndicoID to the existing record of the LOID in micala DB (no need to create a new record, because the user is only allowed to choose LOID's that are already in the micala DB) - calls submitMicalaMetadata(), which generates the micala lecture.xml and submits it to micala DB. All of these methods update their status to micala DB. """ # Get the MARC XML and submit it to CDS, # then update micala database Status table showing task completed. # do this for both plain_video and web_lecture talks resultCreateCDSRecord = createCDSRecord( self._aw, self._IndicoID, self._LODBID, self._lectureTitle, self._lectureSpeakers, self._contentType, self._videoFormat, self._languages) if resultCreateCDSRecord["success"] == False: raise RecordingManagerException( _("CDS record creation failed.\n%s") % resultCreateCDSRecord["result"]) return _("CDS record creation aborted.") if self._contentType == 'web_lecture': # Update the micala database to match the LODBID with the IndicoID # This only makes sense for web_lecture talks # (for plain_video, a record in Lectures should already have been created by createCDSRecord() ) resultAssociateIndicoIDToLOID = MicalaCommunication.associateIndicoIDToLOID( self._IndicoID, self._params.get('LODBID', None)) if resultAssociateIndicoIDToLOID["success"] == False: raise RecordingManagerException( _("micala database update failed.\n%s") % resultAssociateIndicoIDToLOID["result"]) return _("CDS record creation aborted.") # Create lecture.xml and submit to micala server, # then update micala database Status table showing task completed # (this only makes sense if it is a web_lecture) resultSubmitMicalaMetadata = submitMicalaMetadata( self._aw, self._IndicoID, self._contentType, self._LODBID, self._params.get('LOID', None), self._videoFormat, self._languages) if resultSubmitMicalaMetadata["success"] == False: raise RecordingManagerException( _("CDS record creation failed.\n%s") % resultSubmitMicalaMetadata["result"]) return _("micala metadata creation aborted.") return _( "Successfully updated micala database and submitted CDS record for creation." )
def _getAnswer(self): """This method does everything necessary to create a CDS record and also update the micala database. For plain_video talks, it does the following: - calls createCDSRecord(), which generates the MARC XML, submits it to CDS, and makes sure a record for this talk exists in micala DB For web_lecture talks, it does the following: - calls createCDSRecord(), which generates the MARC XML and submits it to CDS - calls associateIndicoIDToLOID(), which associates the chosen IndicoID to the existing record of the LOID in micala DB (no need to create a new record, because the user is only allowed to choose LOID's that are already in the micala DB) - calls submitMicalaMetadata(), which generates the micala lecture.xml and submits it to micala DB. All of these methods update their status to micala DB. """ # Get the MARC XML and submit it to CDS, # then update micala database Status table showing task completed. # do this for both plain_video and web_lecture talks resultCreateCDSRecord = createCDSRecord(self._aw, self._IndicoID, self._LODBID, self._lectureTitle, self._lectureSpeakers, self._contentType, self._videoFormat, self._languages) if resultCreateCDSRecord["success"] == False: raise RecordingManagerException(_("CDS record creation failed.\n%s") % resultCreateCDSRecord["result"]) return _("CDS record creation aborted.") if self._contentType == 'web_lecture': # Update the micala database to match the LODBID with the IndicoID # This only makes sense for web_lecture talks # (for plain_video, a record in Lectures should already have been created by createCDSRecord() ) resultAssociateIndicoIDToLOID = MicalaCommunication.associateIndicoIDToLOID(self._IndicoID, self._params.get('LODBID', None)) if resultAssociateIndicoIDToLOID["success"] == False: raise RecordingManagerException(_("micala database update failed.\n%s") % resultAssociateIndicoIDToLOID["result"]) return _("CDS record creation aborted.") # Create lecture.xml and submit to micala server, # then update micala database Status table showing task completed # (this only makes sense if it is a web_lecture) resultSubmitMicalaMetadata = submitMicalaMetadata(self._aw, self._IndicoID, self._contentType, self._LODBID, self._params.get('LOID', None), self._videoFormat, self._languages) if resultSubmitMicalaMetadata["success"] == False: raise RecordingManagerException(_("CDS record creation failed.\n%s") % resultSubmitMicalaMetadata["result"]) return _("micala metadata creation aborted.") return _("Successfully updated micala database and submitted CDS record for creation.")
def submitMicalaMetadata(aw, IndicoID, contentType, LODBID, LOID, videoFormat, languages): '''Generate a lecture.xml file for the given event, then web upload it to the micala server.''' # Logger.get('RecMan').debug('in submitMicalaMetadata()') # Initialize success flag, and result string to which we will append any errors. flagSuccess = True result = "" # First update the micala database that we've started this task try: idMachine = MicalaCommunication.getIdMachine(CollaborationTools.getOptionValue("RecordingManager", "micalaDBMachineName")) idTask = MicalaCommunication.getIdTask(CollaborationTools.getOptionValue("RecordingManager", "micalaDBStatusExportMicala")) idLecture = LODBID # Logger.get('RecMan').debug('submitMicalaMetadata calling reportStatus...') MicalaCommunication.reportStatus('START', '', idMachine, idTask, idLecture) except Exception, e: flagSuccess = False result += _("Unknown error occured when updating MICALA START task information in micala database: %s\n.") % e
def getTalks(conference, sort = False): """ sort: if True, contributions are sorted by start date (non scheduled contributions at the end) """ # Logger.get('RecMan').debug("in getTalks()") # max length for title string title_length = 39 # recordable_events is my own list of tags for each recordable event # which will be used by the tpl file. recordable_events = [] talks = [] speaker_str = "" speaker_list = conference.getChairList() if speaker_list is not None: speaker_str = ", ".join(["%s %s"%(speaker.getFirstName(), speaker.getFamilyName()) for speaker in speaker_list]) event_info = {} event_info["contId"] = "" event_info["speakers"] = speaker_str event_info["type"] = "conference" event_info["IndicoID"] = generateIndicoID(conference = conference.getId(), session = None, contribution = None, subcontribution = None) event_info["title"] = conference.getTitle() event_info["titleshort"] = truncateString(event_info["title"], 40) # this always comes first, so just pretend it's 0 seconds past the epoch event_info["date"] = int(time.mktime(conference.getAdjustedStartDate().timetuple())) event_info["LOID"] = "" event_info["IndicoLink"] = doesExistIndicoLink(conference) recordable_events.append(event_info) # Posters are contributions that are not recordable, # so filter them out here filter = PosterFilterField(conference, False, False) for contribution in conference.getContributionList(): if filter.satisfies(contribution): talks.append(contribution) speaker_str = "" speaker_list = contribution.getSpeakerList() if speaker_list is not None: speaker_str = ", ".join(["%s %s"%(speaker.getFirstName(), speaker.getFamilyName()) for speaker in speaker_list]) event_info = {} event_info["contId"] = contribution.getId() event_info["speakers"] = speaker_str event_info["type"] = "contribution" event_info["IndicoID"] = generateIndicoID(conference = conference.getId(), session = None, contribution = contribution.getId(), subcontribution = None) event_info["title"] = contribution.getTitle() event_info["titleshort"] = truncateString(event_info["title"], title_length) # Sometimes contributions are not scheduled, so they have no start date. # In this case assign it the value None, and it will be displayed # at the end of the list with the time value "not scheduled" if contribution.getAdjustedStartDate() is not None: event_info["date"] = int(time.mktime(contribution.getAdjustedStartDate().timetuple())) else: event_info["date"] = None event_info["LOID"] = "" event_info["IndicoLink"] = doesExistIndicoLink(contribution) recordable_events.append(event_info) ctr_sc = 0 for subcontribution in contribution.getSubContributionList(): ctr_sc += 1 event_info = {} event_info["contId"] = contribution.getId() speaker_str = "" speaker_list = subcontribution.getSpeakerList() if speaker_list is not None: speaker_str = ", ".join(["%s %s"%(speaker.getFirstName(), speaker.getFamilyName()) for speaker in speaker_list]) event_info["speakers"] = speaker_str event_info["type"] = "subcontribution" event_info["IndicoID"] = generateIndicoID(conference = conference.getId(), session = None, contribution = contribution.getId(), subcontribution = subcontribution.getId()) event_info["title"] = subcontribution.getTitle() event_info["titleshort"] = truncateString(event_info["title"], title_length) # Subcontribution objects don't have start dates, # so get the owner contribution's start date # and add the counter ctr_sc so they appear in order if subcontribution.getOwner().getAdjustedStartDate() is not None: event_info["date"] = int(time.mktime(subcontribution.getOwner().getAdjustedStartDate().timetuple()) + ctr_sc) else: event_info["date"] = int(time.mktime(conference.getAdjustedStartDate().timetuple())) + ctr_sc event_info["LOID"] = "" event_info["IndicoLink"] = doesExistIndicoLink(subcontribution) recordable_events.append(event_info) for session in conference.getSessionList(): event_info = {} event_info["contId"] = "" event_info["speakers"] = "" event_info["type"] = "session" event_info["IndicoID"] = generateIndicoID(conference = conference.getId(), session = session.getId(), contribution = None, subcontribution = None) event_info["title"] = session.getTitle() event_info["titleshort"] = truncateString(event_info["title"], title_length) # Get start time as seconds since the epoch so we can sort if session.getAdjustedStartDate() is not None: event_info["date"] = int(time.mktime(session.getAdjustedStartDate().timetuple())) else: event_info["date"] = None event_info["LOID"] = "" event_info["IndicoLink"] = doesExistIndicoLink(session) recordable_events.append(event_info) # Get list of matching IndicoIDs and CDS records from CDS cds_indico_matches = getCDSRecords(conference.getId()) # Logger.get('RecMan').debug('cds_indico_pending...') cds_indico_pending = MicalaCommunication.getCDSPending(conference.getId()) # In case there are any records that were pending and are now appearing in CDS, # then update the micala database accordingly. MicalaCommunication.updateMicalaCDSExport(cds_indico_matches, cds_indico_pending) # Logger.get('RecMan').debug("cds_indico_matches: %s, cds_indico_pending: %s" % (cds_indico_matches, cds_indico_pending)) for event_info in recordable_events: try: event_info["CDSID"] = cds_indico_matches[event_info["IndicoID"]] event_info["CDSURL"] = CollaborationTools.getOptionValue("RecordingManager", "CDSBaseURL") % event_info["CDSID"] except KeyError: # Logger.get('RecMan').debug("Following talk not in CDS: %s" % event_info["title"]) if cds_indico_pending is not None and event_info["IndicoID"] in set(cds_indico_pending): event_info["CDSID"] = 'pending' event_info["CDSURL"] = "" else: event_info["CDSID"] = "none" event_info["CDSURL"] = "" # Get list of matching IndicoID's and LOIDs from the Micala database existing_matches = MicalaCommunication.getMatches(conference.getId()) # insert any existing matches into the recordable_events array for talk in recordable_events: # Look up IndicoID in existing_matches dictionary try: matching_LOID = existing_matches[talk["IndicoID"]] # If not found, do nothing (talk["LOID"] should already be assigned to "" by default) except KeyError: pass # If there is a matching_LOID, assign it to talk["LOID"] else: talk["LOID"] = matching_LOID # Now that we have all the micala, CDS and IndicoLink info, set up the bg images for talk in recordable_events: talk["bg"] = chooseBGColor(talk) # Format dates for each talk for pleasing display for talk in recordable_events: talk["date_nice"] = formatDate(talk["date"]) # Next, sort the list of events by startDate for display purposes recordable_events.sort(startTimeCompare) # Logger.get('RecMan').debug('leaving getTalks()') return recordable_events
flagSuccess = True result = "" try: connection = MySQLdb.connect(host = CollaborationTools.getOptionValue("RecordingManager", "micalaDBServer"), port = int(CollaborationTools.getOptionValue("RecordingManager", "micalaDBPort")), user = CollaborationTools.getOptionValue("RecordingManager", "micalaDBReaderUser"), passwd = CollaborationTools.getOptionValue("RecordingManager", "micalaDBReaderPW"), db = CollaborationTools.getOptionValue("RecordingManager", "micalaDBName")) except NameError: raise MaKaCError("You need to install MySQLdb (python-mysql) in order to use the Recording Manager") except MySQLdb.Error, e: flagSuccess = False result += "MySQL error %d: %s" % (e.args[0], e.args[1]) idTaskRecording = MicalaCommunication.getIdTask("recording") if flagSuccess == True: try: cursor = connection.cursor(cursorclass=MySQLdb.cursors.DictCursor) # Query Lectures table for all records in which IndicoID is blank or NULL cursor.execute("""SELECT L.idLecture AS idLecture, L.LOID AS LOID, L.IndicoID AS IndicoID, M.Hostname AS Hostname, V.RoomName AS RoomName, L.Duration AS Duration FROM Lectures L, LectureLatestStatus LS, Status S, Machines M, Venues V WHERE LS.idLecture = L.idLecture AND LS.idTask = %s AND LS.idStatus = S.idStatus AND S.idMachine = M.idMachine AND M.idVenue = V.idVenue AND (NOT L.IndicoID OR L.IndicoID IS NULL) ORDER BY L.LOID""", (idTaskRecording,))
def getTalks(conference, sort=False): """ sort: if True, contributions are sorted by start date (non scheduled contributions at the end) """ # Logger.get('RecMan').debug("in getTalks()") # max length for title string title_length = 39 # recordable_events is my own list of tags for each recordable event # which will be used by the tpl file. recordable_events = [] talks = [] speaker_str = "" speaker_list = conference.getChairList() if speaker_list is not None: speaker_str = ", ".join([ "%s %s" % (speaker.getFirstName(), speaker.getFamilyName()) for speaker in speaker_list ]) event_info = {} event_info["contId"] = "" event_info["speakers"] = speaker_str event_info["type"] = "conference" event_info["IndicoID"] = generateIndicoID(conference=conference.getId(), session=None, contribution=None, subcontribution=None) event_info["title"] = conference.getTitle() event_info["titleshort"] = truncate(event_info["title"], 40) # this always comes first, so just pretend it's 0 seconds past the epoch event_info["date"] = int( time.mktime(conference.getAdjustedStartDate().timetuple())) event_info["LOID"] = "" event_info["IndicoLink"] = doesExistIndicoLink(conference) recordable_events.append(event_info) # Posters are contributions that are not recordable, # so filter them out here filter = PosterFilterField(conference, False, False) for contribution in conference.getContributionList(): if filter.satisfies(contribution): talks.append(contribution) speaker_str = "" speaker_list = contribution.getSpeakerList() if speaker_list is not None: speaker_str = ", ".join([ "%s %s" % (speaker.getFirstName(), speaker.getFamilyName()) for speaker in speaker_list ]) event_info = {} event_info["contId"] = contribution.getId() event_info["speakers"] = speaker_str event_info["type"] = "contribution" event_info["IndicoID"] = generateIndicoID( conference=conference.getId(), session=None, contribution=contribution.getId(), subcontribution=None) event_info["title"] = contribution.getTitle() event_info["titleshort"] = truncate(event_info["title"], title_length) # Sometimes contributions are not scheduled, so they have no start date. # In this case assign it the value None, and it will be displayed # at the end of the list with the time value "not scheduled" if contribution.getAdjustedStartDate() is not None: event_info["date"] = int( time.mktime( contribution.getAdjustedStartDate().timetuple())) else: event_info["date"] = None event_info["LOID"] = "" event_info["IndicoLink"] = doesExistIndicoLink(contribution) recordable_events.append(event_info) ctr_sc = 0 for subcontribution in contribution.getSubContributionList(): ctr_sc += 1 event_info = {} event_info["contId"] = contribution.getId() speaker_str = "" speaker_list = subcontribution.getSpeakerList() if speaker_list is not None: speaker_str = ", ".join([ "%s %s" % (speaker.getFirstName(), speaker.getFamilyName()) for speaker in speaker_list ]) event_info["speakers"] = speaker_str event_info["type"] = "subcontribution" event_info["IndicoID"] = generateIndicoID( conference=conference.getId(), session=None, contribution=contribution.getId(), subcontribution=subcontribution.getId()) event_info["title"] = subcontribution.getTitle() event_info["titleshort"] = truncate(event_info["title"], title_length) # Subcontribution objects don't have start dates, # so get the owner contribution's start date # and add the counter ctr_sc so they appear in order if subcontribution.getOwner().getAdjustedStartDate( ) is not None: event_info["date"] = int( time.mktime(subcontribution.getOwner( ).getAdjustedStartDate().timetuple()) + ctr_sc) else: event_info["date"] = int( time.mktime(conference.getAdjustedStartDate(). timetuple())) + ctr_sc event_info["LOID"] = "" event_info["IndicoLink"] = doesExistIndicoLink(subcontribution) recordable_events.append(event_info) for session in conference.getSessionList(): event_info = {} event_info["contId"] = "" event_info["speakers"] = "" event_info["type"] = "session" event_info["IndicoID"] = generateIndicoID( conference=conference.getId(), session=session.getId(), contribution=None, subcontribution=None) event_info["title"] = session.getTitle() event_info["titleshort"] = truncate(event_info["title"], title_length) # Get start time as seconds since the epoch so we can sort if session.getAdjustedStartDate() is not None: event_info["date"] = int( time.mktime(session.getAdjustedStartDate().timetuple())) else: event_info["date"] = None event_info["LOID"] = "" event_info["IndicoLink"] = doesExistIndicoLink(session) recordable_events.append(event_info) # Get list of matching IndicoIDs and CDS records from CDS cds_indico_matches = getCDSRecords(conference.getId()) # Logger.get('RecMan').debug('cds_indico_pending...') cds_indico_pending = MicalaCommunication.getCDSPending(conference.getId()) # In case there are any records that were pending and are now appearing in CDS, # then update the micala database accordingly. MicalaCommunication.updateMicalaCDSExport(cds_indico_matches, cds_indico_pending) # Logger.get('RecMan').debug("cds_indico_matches: %s, cds_indico_pending: %s" % (cds_indico_matches, cds_indico_pending)) for event_info in recordable_events: try: event_info["CDSID"] = cds_indico_matches[event_info["IndicoID"]] event_info["CDSURL"] = CollaborationTools.getOptionValue( "RecordingManager", "CDSBaseURL") % event_info["CDSID"] except KeyError: # Logger.get('RecMan').debug("Following talk not in CDS: %s" % event_info["title"]) if cds_indico_pending is not None and event_info[ "IndicoID"] in set(cds_indico_pending): event_info["CDSID"] = 'pending' event_info["CDSURL"] = "" else: event_info["CDSID"] = "none" event_info["CDSURL"] = "" # Get list of matching IndicoID's and LOIDs from the Micala database existing_matches = MicalaCommunication.getMatches(conference.getId()) # insert any existing matches into the recordable_events array for talk in recordable_events: # Look up IndicoID in existing_matches dictionary try: matching_LOID = existing_matches[talk["IndicoID"]] # If not found, do nothing (talk["LOID"] should already be assigned to "" by default) except KeyError: pass # If there is a matching_LOID, assign it to talk["LOID"] else: talk["LOID"] = matching_LOID # Now that we have all the micala, CDS and IndicoLink info, set up the bg images for talk in recordable_events: talk["bg"] = chooseBGColor(talk) # Format dates for each talk for pleasing display for talk in recordable_events: talk["date_nice"] = formatDate(talk["date"]) # Next, sort the list of events by startDate for display purposes recordable_events.sort(startTimeCompare) # Logger.get('RecMan').debug('leaving getTalks()') return recordable_events
"micalaDBPort")), user=CollaborationTools.getOptionValue("RecordingManager", "micalaDBReaderUser"), passwd=CollaborationTools.getOptionValue("RecordingManager", "micalaDBReaderPW"), db=CollaborationTools.getOptionValue("RecordingManager", "micalaDBName")) except NameError: raise MaKaCError( "You need to install MySQLdb (python-mysql) in order to use the Recording Manager" ) except MySQLdb.Error, e: flagSuccess = False result += "MySQL error %d: %s" % (e.args[0], e.args[1]) idTaskRecording = MicalaCommunication.getIdTask("recording") if flagSuccess == True: try: cursor = connection.cursor(cursorclass=MySQLdb.cursors.DictCursor) # Query Lectures table for all records in which IndicoID is blank or NULL cursor.execute( """SELECT L.idLecture AS idLecture, L.LOID AS LOID, L.IndicoID AS IndicoID, M.Hostname AS Hostname, V.RoomName AS RoomName, L.Duration AS Duration FROM Lectures L, LectureLatestStatus LS, Status S, Machines M, Venues V WHERE LS.idLecture = L.idLecture AND LS.idTask = %s AND LS.idStatus = S.idStatus AND S.idMachine = M.idMachine AND M.idVenue = V.idVenue AND L.IndicoID IS NULL ORDER BY L.LOID""", (idTaskRecording, ))