Skip to content
Permalink
Browse files

Fix lockTuner() and freeTuner() methods of MythBE. They relied on

database access methods that had been removed prior to 0.23.
  • Loading branch information
wagnerrp committed Mar 20, 2011
1 parent d6972cf commit 5fd4a102989336841628b9764f2d7fe07162089f
Showing with 61 additions and 32 deletions.
  1. +61 −32 mythtv/bindings/python/MythTV/methodheap.py
@@ -9,7 +9,7 @@
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 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 @@ def lockTuner(self,id=None):
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):
"""

0 comments on commit 5fd4a10

Please sign in to comment.
You can’t perform that action at this time.