| Trees | Indices | Help |
|---|
|
|
1 # -*- Mode: Python -*- 2 # vi:si:et:sw=4:sts=4:ts=4 3 # 4 # Flumotion - a streaming media server 5 # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 6 # All rights reserved. 7 8 # This file may be distributed and/or modified under the terms of 9 # the GNU General Public License version 2 as published by 10 # the Free Software Foundation. 11 # This file is distributed without any warranty; without even the implied 12 # warranty of merchantability or fitness for a particular purpose. 13 # See "LICENSE.GPL" in the source distribution for more information. 14 15 # Licensees having purchased or holding a valid Flumotion Advanced 16 # Streaming Server license may use this file in accordance with the 17 # Flumotion Advanced Streaming Server Commercial License Agreement. 18 # See "LICENSE.Flumotion" in the source distribution for more information. 19 20 # Headers in this file shall remain intact. 21 22 """ 23 A bouncer that only lets in during an event scheduled with an ical file. 24 """ 25 26 from twisted.internet import defer 27 28 from flumotion.common import keycards, errors 29 from flumotion.component.bouncers import bouncer 30 from flumotion.common.keycards import KeycardGeneric 31 from datetime import datetime 32 from flumotion.component.base import scheduler 33 34 __all__ = ['IcalBouncer'] 35 __version__ = "$Rev: 6995 $" 36 37 38 try: 39 # icalendar and dateutil modules needed for ical parsing 40 from icalendar import Calendar 41 from dateutil import rrule 42 HAS_ICAL = True 43 except ImportError: 44 HAS_ICAL = False 4547 48 logCategory = 'icalbouncer' 49 keycardClasses = (KeycardGeneric) 50 events = [] 519153 if not HAS_ICAL: 54 return defer.fail( 55 errors.ConfigError( 56 "Please install icalendar and dateutil modules")) 57 props = self.config['properties'] 58 self._icsfile = props['file'] 59 self.icalScheduler = scheduler.ICalScheduler(open( 60 self._icsfile, 'r')) 61 62 return True6365 self.debug('authenticating keycard') 66 67 # need to check if inside an event time 68 # FIXME: think of a strategy for handling overlapping events 69 currentEvents = self.icalScheduler.getCurrentEvents() 70 if currentEvents: 71 event = currentEvents[0] 72 keycard.state = keycards.AUTHENTICATED 73 now = datetime.now() 74 nowInTz = datetime(now.year, now.month, now.day, 75 now.hour, now.minute, now.second, 76 tzinfo=scheduler.LOCAL) 77 end = event.currentEnd 78 duration = end - nowInTz 79 durationSecs = duration.days * 86400 + duration.seconds 80 keycard.duration = durationSecs 81 self.addKeycard(keycard) 82 self.info("authenticated login") 83 return keycard 84 self.info("failed in authentication, outside hours") 85 return None8688 self.icalScheduler.stopWatchingIcalFile() 89 for event in self.icalScheduler.getCurrentEvents(): 90 self.icalScheduler.removeEvent(event)
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Sat Jul 26 09:43:10 2008 | http://epydoc.sourceforge.net |