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:15:40 (GMT)
commit5fd4a102989336841628b9764f2d7fe07162089f (patch)
treeee8a204236d41de8df15b68ef00f1317fd9f73f4
parentd6972cf5af6eaf9d1c870ced7e20ffa5f0b70af7 (diff)
Fix lockTuner() and freeTuner() methods of MythBE. They relied on
database access methods that had been removed prior to 0.23.
-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 73a4212..2ed2555 100644
--- a/mythtv/bindings/python/MythTV/methodheap.py
+++ b/mythtv/bindings/python/MythTV/methodheap.py
@@ -9,7 +9,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 *
@@ -19,6 +19,9 @@ from weakref import proxy
from urllib import urlopen
import re
+class CaptureCard( DBData ):
+ pass
+
class MythBE( FileOps ):
__doc__ = FileOps.__doc__+"""
getPendingRecordings() - returns a list of scheduled recordings
@@ -49,7 +52,7 @@ class MythBE( FileOps ):
and dictionary of filenames with sizes
"""
- locked_tuners = []
+ locked_tuners = {}
def __del__(self):
self.freeTuner()
@@ -109,51 +112,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):
"""