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, config 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 36 try: 37 # icalendar and dateutil modules needed for ical parsing 38 from icalendar import Calendar 39 from dateutil import rrule 40 HAS_ICAL = True 41 except: 42 HAS_ICAL = False 4345 46 logCategory = 'icalbouncer' 47 keycardClasses = (KeycardGeneric) 48 events = [] 497951 if not HAS_ICAL: 52 return defer.fail( 53 config.ConfigError( 54 "Please install icalendar and dateutil modules")) 55 props = self.config['properties'] 56 self._icsfile = props['file'] 57 self.icalScheduler = scheduler.ICalScheduler(open( 58 self._icsfile, 'r')) 59 60 return True6163 self.debug('authenticating keycard') 64 65 # need to check if inside an event time 66 # FIXME: think of a strategy for handling overlapping events 67 currentEvents = self.icalScheduler.getCurrentEvents() 68 if currentEvents: 69 event = currentEvents[0] 70 keycard.state = keycards.AUTHENTICATED 71 duration = event.end - datetime.now() 72 durationSecs = duration.days * 86400 + duration.seconds 73 keycard.duration = durationSecs 74 self.addKeycard(keycard) 75 self.info("autheticated login") 76 return keycard 77 self.info("failed in authentication, outside hours") 78 return None
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Aug 7 15:03:05 2008 | http://epydoc.sourceforge.net |