def test_ical_get_delete_events(self): old_events = ical.get_events_from_file_ical(path.join(self.base_dir, 'test.ical')) new_events = ical.get_events_from_file_ical(path.join(self.base_dir, 'none.ical')) delete_events = ical.get_delete_events(old_events, new_events) self.assertEqual(len(delete_events), 2)
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 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