Author: duncan
Date: Thu Feb 14 13:09:38 2008
New Revision: 10368
Log:
Tidied the code up a bit and change the order of the functions
Modified:
branches/rel-1/freevo/src/tv/record_client.py
Modified: branches/rel-1/freevo/src/tv/record_client.py
==============================================================================
--- branches/rel-1/freevo/src/tv/record_client.py (original)
+++ branches/rel-1/freevo/src/tv/record_client.py Thu Feb 14 13:09:38 2008
@@ -49,11 +49,8 @@
class RecordClientException(Exception):
- """
- """
+ """ RecordClientException """
def __init__(self):
- """
- """
pass
@@ -62,14 +59,19 @@
recordserver access class using kaa.rpc
"""
def __init__(self):
- """
- """
+ """ """
_debug_('RecordClient.__init__()', 2)
self.socket = (config.RECORDSERVER_IP, config.RECORDSERVER_PORT2)
self.secret = config.RECORDSERVER_SECRET
self.server = None
+ def timeit(self, start=None):
+ if start is None:
+ return time.strftime("%M:%S", time.localtime(time.time()))
+ return '%.3f' % (time.time() - start)
+
+
def recordserver_rpc(self, cmd, *args, **kwargs):
""" call the record server command using kaa rpc """
def closed_handler():
@@ -97,6 +99,18 @@
return None
+ def findNextProgramNow(self, isrecording=False):
+ """ Find the next programme to record """
+ _debug_('findNextProgramNow(isrecording=%r)' % (isrecording,), 2)
+ progress = self.recordserver_rpc('findNextProgram', isrecording)
+ if progress is None:
+ return None
+ progress.wait()
+ result = progress.get_result()
+ _debug_('findNextProgramNow.result=%r' % (result,), 2)
+ return result
+
+
def getScheduledRecordingsNow(self):
""" get the scheduled recordings, returning the scheduled recordings
object """
_debug_('getScheduledRecordingsNow()', 2)
@@ -118,40 +132,27 @@
progress.wait()
result = progress.get_result()
_debug_('getScheduledRecordingsNow.result=%r' % (result,), 2)
- print 'getScheduledRecordingsNow.result=%r' % (result,)
- return result
-
-
- def findNextProgramNow(self, isrecording=False):
- """ Find the next programme to record """
- _debug_('findNextProgramNow(isrecording=%r)' % (isrecording,), 2)
- progress = self.recordserver_rpc('findNextProgram', isrecording)
- if progress is None:
- return None
- progress.wait()
- result = progress.get_result()
- _debug_('findNextProgramNow.result=%r' % (result,), 2)
return result
+ #yield kaa.NotFinished
@kaa.coroutine()
def getNextProgramStart(self):
""" """
global nextstart
- print 'getNextProgramStart begin'
+ print self.timeit()+': getNextProgramStart begin'
progress = self.recordserver_rpc('updateFavoritesSchedule')
- print 'getNextProgramStart.progress=%r' % progress
- #yield kaa.YieldContinue
+ print self.timeit()+': getNextProgramStart.progress=%r' % progress
yield progress
- print 'getNextProgramStart.progress=%r' % progress
+ print self.timeit()+': getNextProgramStart.progress=%r' % progress
result = progress.get_result()
- print 'getNextProgramme.result=%r' % result
+ print self.timeit()+': getNextProgramme.result=%r' % result
progress = self.recordserver_rpc('findNextProgram')
- print 'getNextProgramStart.progress=%r' % progress
+ print self.timeit()+': getNextProgramStart.progress=%r' % progress
yield progress
- print 'getNextProgramStart.progress=%r' % progress
+ print self.timeit()+': getNextProgramStart.progress=%r' % progress
nextstart = progress.get_result()
- print 'getNextProgramme.nextstart=%r' % nextstart
+ print self.timeit()+': getNextProgramme.nextstart=%r' % nextstart
def server_rpc(self, cmd, callback, *args, **kwargs):
@@ -191,18 +192,18 @@
return self.server_rpc('ping', callback)
- def getScheduledRecordings(self, callback):
- """ Get the scheduled recordings, using a callback function """
- _debug_('getScheduledRecordings(callback=%r)' % (callback), 2)
- return self.server_rpc('getScheduledRecordings', callback)
-
-
def findNextProgram(self, callback, isrecording=False):
""" Find the next program using a callback function """
_debug_('findNextProgram(callback=%r, isrecording=%r)' % (callback,
isrecording), 2)
return self.server_rpc('findNextProgram', callback, isrecording)
+ def getScheduledRecordings(self, callback):
+ """ Get the scheduled recordings, using a callback function """
+ _debug_('getScheduledRecordings(callback=%r)' % (callback), 2)
+ return self.server_rpc('getScheduledRecordings', callback)
+
+
def updateFavoritesSchedule(self, callback):
""" Update the favourites using a callback function """
print 'updateFavoritesSchedule(callback=%r)' % (callback)
@@ -234,6 +235,18 @@
return (status, response)
+def connectionTest(teststr='testing'):
+ """ Using Twisted check if the record server is running """
+ _debug_('connectionTest(teststr=%r)' % (teststr), 2)
+ try:
+ (status, message) = server.echotest(teststr)
+ except Exception, e:
+ _debug_('%s' % e)
+ traceback.print_exc()
+ return (FALSE, 'record_client: '+_('connection error'))
+ return (status, message)
+
+
def getScheduledRecordings():
""" Using Twisted get the scheduled recordings """
_debug_('getScheduledRecordings()', 2)
@@ -255,18 +268,6 @@
return (status, message)
-def connectionTest(teststr='testing'):
- """ Using Twisted check if the record server is running """
- _debug_('connectionTest(teststr=%r)' % (teststr), 2)
- try:
- (status, message) = server.echotest(teststr)
- except Exception, e:
- _debug_('%s' % e)
- traceback.print_exc()
- return (FALSE, 'record_client: '+_('connection error'))
- return (status, message)
-
-
def scheduleRecording(prog=None):
""" Using Twisted add a programme to recording schedule """
_debug_('scheduleRecording(prog=%r)' % (prog), 2)
@@ -500,25 +501,29 @@
print 'xml_rpc_server at %r' % (xml_rpc_server)
- if function == "test":
- (result, response) = connectionTest('connection test')
- print 'result: %s, response: %s ' % (result, response)
+
#--------------------------------------------------------------------------------
+ # kaa.rpc coroutine tests
+
#--------------------------------------------------------------------------------
if function == "getnextprogramstart":
rc.getNextProgramStart()
+
#--------------------------------------------------------------------------------
+ # kaa.rpc callback tests
+
#--------------------------------------------------------------------------------
+
if function == "findnextprogramnow":
result = rc.findNextProgramNow(True)
print 'recording:', result
result = rc.findNextProgramNow(False)
print ' :', result
- if function == "findnextprogramrecording":
- rc.findNextProgram(handler, True)
-
if function == "findnextprogram":
rc.findNextProgram(handler)
+ if function == "findnextprogramrecording":
+ rc.findNextProgram(handler, True)
+
if function == "getscheduledrecordingsnow":
result = rc.getScheduledRecordingsNow()
print 'result: %r' % (result,)
@@ -527,12 +532,21 @@
rc.getScheduledRecordings(handler)
if function == "updatefavoritesschedulenow":
+ start = time.time()
result = rc.updateFavoritesScheduleNow()
- print 'result: %r' % (result,)
+ print '%s: result: %r' % (rc.timeit(start), result)
if function == "updatefavoritesschedule":
rc.updateFavoritesSchedule(handler)
+
#--------------------------------------------------------------------------------
+ # Twisted xmlrpc tests
+
#--------------------------------------------------------------------------------
+
+ if function == "test":
+ (result, response) = connectionTest('connection test')
+ print 'result: %s, response: %s ' % (result, response)
+
if function == "getfavorites":
(result, response) = getFavorites()
print '%r' % response
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog