def test_ical_create_mp_update(self): repo = repository.Repository(self.tmppath) events = ical.get_events_from_file_ical(path.join(self.base_dir, 'create_mp_original.ical')) for event in events: ical.create_mp(repo, event) next = repo.get_next_mediapackage() self.assertEqual(next.getDate(), datetime.strptime('3018-10-17 08:00:00', '%Y-%m-%d %H:%M:%S')) self.assertEqual(len(next.getElements()), 3) self.assertEqual(len(next.getAttachments()), 1) self.assertTrue(next.getAttachment('org.opencastproject.capture.agent.properties')) self.assertEqual(len(next.getCatalogs()), 2) self.assertEqual(next.getTitle(), "EVENTO ORIGINAL") self.assertEqual(next.getSeriesTitle(), "New") self.assertEqual(next.getDuration(), 1000*60*83) # 1h 23min events = ical.get_events_from_file_ical(path.join(self.base_dir, 'create_mp_updated.ical')) for event in events: ical.create_mp(repo, event) next = repo.get_next_mediapackage() self.assertEqual(next.getDate(), datetime.strptime('3018-10-17 08:00:00', '%Y-%m-%d %H:%M:%S')) self.assertEqual(len(next.getElements()), 3) self.assertEqual(len(next.getAttachments()), 1) self.assertTrue(next.getAttachment('org.opencastproject.capture.agent.properties')) self.assertEqual(len(next.getCatalogs()), 2) self.assertEqual(next.getTitle(), "EVENTO MODIFICADO") self.assertEqual(next.getSeriesTitle(), "New") self.assertEqual(next.getDuration(), 1000*60*83) # 1h 23min
def proccess_ical(self): logger.info('Proccess ical') try: ical_data = self.client.ical() except: logger.warning('Problems to connect to matterhorn server ') self.net = False self.dispatcher.emit('net-down') return try: events = ical.get_events_from_string_ical(ical_data) delete_events = ical.get_delete_events(self.last_events, events) update_events = ical.get_update_events(self.last_events, events) except: logger.error('Error proccessing ical') return self.repo.save_attach('calendar.ical', ical_data) for event in events: logger.info('Creating MP with UID {0} from ical'.format( event['UID'])) ical.create_mp(self.repo, event) for event in delete_events: logger.info('Deleting MP with UID {0} from ical'.format( event['UID'])) mp = self.repo.get(event['UID']) if mp.status == mediapackage.SCHEDULED: self.repo.delete(mp) if self.start_timers.has_key(mp.getIdentifier()): self.start_timers[mp.getIdentifier()].cancel() del self.start_timers[mp.getIdentifier()] for event in update_events: logger.info('Updating MP with UID {0} from ical'.format( event['UID'])) mp = self.repo.get(event['UID']) if self.start_timers.has_key(mp.getIdentifier( )) and mp.status == mediapackage.SCHEDULED: self.start_timers[mp.getIdentifier()].cancel() del self.start_timers[mp.getIdentifier()] self.__create_new_timer(mp) for mp in self.repo.get_next_mediapackages(): self.__create_new_timer(mp) self.last_events = events
def proccess_ical(self): """Creates, deletes or updates mediapackages according to scheduled events information given by opencast. """ self.logger.info('Proccess ical') try: ical_data = self.client.ical() except Exception as exc: self.logger.warning('Problems to connect to opencast server: {0}'.format(exc)) self.net = False self.emit('net-down') return # No data but no error implies that the calendar has not been modified (ETAG) if ical_data == None: return try: events = ical.get_events_from_string_ical(ical_data) delete_events = ical.get_delete_events(self.last_events, events) update_events = ical.get_update_events(self.last_events, events) except Exception as exc: self.logger.error('Error proccessing ical: {0}'.format(exc)) return self.repo.save_attach('calendar.ical', ical_data) for event in events: self.logger.debug('Creating MP with UID {0} from ical'.format(event['UID'])) ical.create_mp(self.repo, event) for event in delete_events: self.logger.info('Deleting MP with UID {0} from ical'.format(event['UID'])) mp = self.repo.get(event['UID']) if mp.status == mediapackage.SCHEDULED: self.repo.delete(mp) if self.start_timers.has_key(mp.getIdentifier()): self.start_timers[mp.getIdentifier()].cancel() del self.start_timers[mp.getIdentifier()] for event in update_events: self.logger.info('Updating MP with UID {0} from ical'.format(event['UID'])) mp = self.repo.get(event['UID']) if self.start_timers.has_key(mp.getIdentifier()) and mp.status == mediapackage.SCHEDULED: self.start_timers[mp.getIdentifier()].cancel() del self.start_timers[mp.getIdentifier()] self.create_new_timer(mp) self.last_events = events
def test_ical_create_mp(self): repo = repository.Repository(self.tmppath) events = ical.get_events_from_file_ical(path.join(self.base_dir, 'test.ical')) for event in events: ical.create_mp(repo, event) next = repo.get_next_mediapackage() self.assertEqual(next.getDate(), datetime.strptime('3012-08-25 17:00:00', '%Y-%m-%d %H:%M:%S')) self.assertEqual(len(next.getElements()), 2) self.assertEqual(len(next.getAttachments()), 1) self.assertTrue(next.getAttachment('org.opencastproject.capture.agent.properties')) self.assertEqual(len(next.getCatalogs()), 1) nexts = repo.get_next_mediapackages() self.assertEqual(nexts[0].getDate(), datetime.strptime('3012-08-25 17:00:00', '%Y-%m-%d %H:%M:%S'))
def proccess_ical(self): logger.info('Proccess ical') try: ical_data = self.client.ical() except: logger.warning('Problems to connect to matterhorn server ') self.net = False self.dispatcher.emit('net-down') return try: events = ical.get_events_from_string_ical(ical_data) delete_events = ical.get_delete_events(self.last_events, events) update_events = ical.get_update_events(self.last_events, events) except: logger.error('Error proccessing ical') return self.repo.save_attach('calendar.ical', ical_data) for event in events: logger.info('Creating MP with UID {0} from ical'.format(event['UID'])) ical.create_mp(self.repo, event) for event in delete_events: logger.info('Deleting MP with UID {0} from ical'.format(event['UID'])) mp = self.repo.get(event['UID']) if mp.status == mediapackage.SCHEDULED: self.repo.delete(mp) if self.start_timers.has_key(mp.getIdentifier()): self.start_timers[mp.getIdentifier()].cancel() del self.start_timers[mp.getIdentifier()] for event in update_events: logger.info('Updating MP with UID {0} from ical'.format(event['UID'])) mp = self.repo.get(event['UID']) if self.start_timers.has_key(mp.getIdentifier()) and mp.status == mediapackage.SCHEDULED: self.start_timers[mp.getIdentifier()].cancel() del self.start_timers[mp.getIdentifier()] self.__create_new_timer(mp) for mp in self.repo.get_next_mediapackages(): self.__create_new_timer(mp) self.last_events = events