summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Wagner <rwagner@mythtv.org>2011-03-20 07:15:40 (GMT)
committer Raymond Wagner <rwagner@mythtv.org>2011-03-20 07:21:39 (GMT)
commit782b652cfce939fee276bb8b23d33d9942e81c5a (patch)
tree055d4c69b4e427d5a0c3a35fb9ef50d9d218653c
parentdb3cfd3273016b741b68541ed322cc89e599a3a1 (diff)
Fix lockTuner() and freeTuner() methods of MythBE. They relied on
database access methods that had been removed prior to 0.23. (cherry picked from commit 5fd4a102989336841628b9764f2d7fe07162089f)
-rw-r--r--mythtv/bindings/python/MythTV/methodheap.py93
1 files changed, 61 insertions, 32 deletions
diff --git a/mythtv/bindings/python/MythTV/methodheap.py b/mythtv/bindings/python/MythTV/methodheap.py
index 553b8ca..3b6ec6a 100644
--- a/mythtv/bindings/python/MythTV/methodheap.py
+++ b/mythtv/bindings/python/MythTV/methodheap.py
@@ -11,7 +11,7 @@ from exceptions import *
from logging import MythLog
from connections import FEConnection, XMLConnection
from utility import databaseSearch, datetime
-from database import DBCache
+from database import DBCache, DBData
from system import SystemEvent
from mythproto import BEEvent, FileOps, Program, FreeSpace
from dataheap import *
@@ -20,6 +20,9 @@ from datetime import timedelta
from weakref import proxy
import re
+class CaptureCard( DBData ):
+ pass
+
class MythBE( FileOps ):
__doc__ = FileOps.__doc__+"""
getPendingRecordings() - returns a list of scheduled recordings
@@ -50,7 +53,7 @@ class MythBE( FileOps ):
and dictionary of filenames with sizes
"""
- locked_tuners = []
+ locked_tuners = {}
def __del__(self):
self.freeTuner()
@@ -110,51 +113,77 @@ class MythBE( FileOps ):
Returns an ID of -2 if tuner is locked
-1 if no tuner could be found
"""
- local = True
cmd = 'LOCK_TUNER'
+ be = self
+
if id is not None:
+ card = None
+ try:
+ # pull information from database to confirm existance
+ card = CaptureCard(id)
+ except MythError:
+ raise MythError("Capture card %s not found" % id)
+
cmd += ' %d' % id
- res = self.getRecorderDetails(id).hostname
- if res != self.localname():
- local = False
+ if card.hostname != be.hostname:
+ # connect to slave backend if needed
+ be = MythBE(card.hostname, db=self.db)
- res = ''
- if local:
- res = self.backendCommand(cmd).split(BACKEND_SEP)
- else:
- myth = MythTV(res)
- res = myth.backendCommand(cmd).split(BACKEND_SEP)
- myth.close()
- res[0] = int(res[0])
- if res[0] > 0:
- self.locked_tuners.append(res[0])
+ res = be.backendCommand(cmd).split(BACKEND_SEP)
+ err = int(res[0])
+
+ if err > 0:
+ # success, store tuner and return device nodes
+ self.locked_tuners[err] = be.hostname
return tuple(res[1:])
- return res[0]
+ # return failure mode
+ return err
def freeTuner(self,id=None):
"""
Frees a requested tuner ID
If no ID given, free all tuners listed as used by this class instance
"""
- def free(self,id):
- res = self.getRecorderDetails(id).hostname
- if res == self.localname():
- self.backendCommand('FREE_TUNER %d' % id)
- else:
- myth = MythTV(res)
- myth.backendCommand('FREE_TUNER %d' % id)
- myth.close()
+ tunerlist = {}
- if id is None:
- for i in xrange(len(self.locked_tuners)):
- free(self,self.locked_tuners.pop())
+ if id is not None:
+ id = int(id)
+ if id in self.locked_tuners:
+ # tuner is known, pop from list
+ tunerlist[id] = self.locked_tuners.pop(id)
+
+ else:
+ # tuner is not known, find hostname
+ try:
+ card = CaptureCard(id)
+ except MythError:
+ raise MythError("Capture card %s not found" % id)
+ tunerlist[id] = card.hostname
else:
+ # use the stored list
+ tunerlist = self.locked_tuners
+
+ hosts = {self.hostname:self}
+
+ while True:
try:
- self.locked_tuners.remove(id)
- except:
- pass
- free(self,id)
+ # get a tuner
+ id, host = tunerlist.popitem()
+
+ # get the backend connection
+ be = None
+ if host in hosts:
+ be = hosts[host]
+ else:
+ be = MythBE(host, db=self.db)
+ hosts[host] = be
+
+ # unlock the tuner
+ be.backendCommand('FREE_TUNER %d' % id)
+ except KeyError:
+ # out of tuners
+ break
def getCurrentRecording(self, recorder):
"""