/usr/lib/python2.7/dist-packages/examples/timestamp.py is in python-starpy 1.0.1.0.git.20140806-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #! /usr/bin/env python
"""Provide a trivial date-and-time service"""
from twisted.internet import reactor
from starpy import fastagi
import logging, time
log = logging.getLogger( 'dateandtime' )
def testFunction( agi ):
"""Give time for some time a bit in the future"""
log.debug( 'testFunction' )
df = agi.streamFile( 'at-tone-time-exactly' )
def onFailed( reason ):
log.error( "Failure: %s", reason.getTraceback())
return None
def cleanup( result ):
agi.finish()
return result
def onSaid( resultLine ):
"""Having introduced, actually read the time"""
t = time.time()
t2 = t+20.0
df = agi.sayDateTime( t2, format='HM' )
def onDateFinished( resultLine ):
# now need to sleep until .5 seconds before the time
df = agi.wait( t2-.5-time.time() )
def onDoBeep( result ):
df = agi.streamFile( 'beep' )
return df
return df.addCallback( onDoBeep )
return df.addCallback( onDateFinished )
return df.addCallback(
onSaid
).addErrback(
onFailed
).addCallbacks(
cleanup, cleanup,
)
if __name__ == "__main__":
logging.basicConfig()
fastagi.log.setLevel( logging.INFO )
f = fastagi.FastAGIFactory(testFunction)
reactor.listenTCP(4574, f, 50, '127.0.0.1') # only binding on local interface
reactor.run()
|