Author: dmeyer
Date: Sun Feb 25 12:20:30 2007
New Revision: 2524
Modified:
trunk/epg/src/__init__.py
trunk/epg/src/channel.py
trunk/epg/src/client.py
trunk/epg/src/server.py
Log:
Make genre ATTR_SEARCHABLE (this requires removing the old db first)
search() now allways returns an InProgress object for async db
queries. The interface in __init__ now has a parameter 'block'
to let the function block until the results arrive.
Modified: trunk/epg/src/__init__.py
==============================================================================
--- trunk/epg/src/__init__.py (original)
+++ trunk/epg/src/__init__.py Sun Feb 25 12:20:30 2007
@@ -34,6 +34,7 @@
import logging
# kaa imports
+import kaa.notifier
from kaa.db import QExpr
# kaa.epg imports
@@ -51,18 +52,16 @@
log = logging.getLogger('epg')
# connected client object
-guide = None
+guide = Client()
def connect(address, auth_secret=''):
"""
Connect to the epg server with the given address.
"""
- global guide
-
- if guide and not guide.status == DISCONNECTED:
+ if not guide.status == DISCONNECTED:
log.warning('connecting to a new epg database')
-
- guide = Client(address, auth_secret)
+ guide.connect(address, auth_secret)
+ guide.connect(address, auth_secret)
return guide
@@ -70,7 +69,7 @@
"""
Return a list of all channels.
"""
- if guide and not guide.status == DISCONNECTED:
+ if not guide.status == DISCONNECTED:
if sort:
channels = guide.get_channels()[:]
channels.sort(lambda a, b: cmp(a.name, b.name))
@@ -84,21 +83,25 @@
"""
Return the channel with the given name.
"""
- if guide and not guide.status == DISCONNECTED:
+ if not guide.status == DISCONNECTED:
return guide.get_channel(name)
return []
-def search(*args, **kwargs):
- """
- Search the epg.
+def search(channel=None, time=None, block=False, **kwargs):
"""
- if guide and not guide.status == DISCONNECTED:
- try:
- return guide.search(*args, **kwargs)
- except Exception, e:
- log.exception('kaa.epg.search failed')
- return []
+ Search the db. This will call the search function on server side using
+ kaa.ipc. This function will return an InProgress object. If block is
+ True the function to block using kaa.notifier.step() until the result
+ arrived from the server.
+ """
+ if block:
+ wait = guide.search(channel, time, **kwargs)
+ while not wait.is_finished:
+ kaa.notifier.step()
+ return wait()
+ return guide.search(channel, time, **kwargs)
+
def is_connected():
return guide and guide.status == CONNECTED
Modified: trunk/epg/src/channel.py
==============================================================================
--- trunk/epg/src/channel.py (original)
+++ trunk/epg/src/channel.py Sun Feb 25 12:20:30 2007
@@ -50,17 +50,5 @@
self.id = name
- def get_programs(self, t = None, callback = None):
- """
- Get programs from a specific time.
- """
- if not t:
- t = time.time()
-
- if self._epg:
- return self._epg.search(time = t, channel = self, callback =
callback)
- else:
- return []
-
def __repr__(self):
return '<kaa.epg.Channel %s>' % self.name
Modified: trunk/epg/src/client.py
==============================================================================
--- trunk/epg/src/client.py (original)
+++ trunk/epg/src/client.py Sun Feb 25 12:20:30 2007
@@ -51,10 +51,9 @@
"""
EPG client class to access the epg on server side.
"""
- def __init__(self, server_or_socket, auth_secret = ''):
- self.status = CONNECTING
- self.server = kaa.rpc.Client(server_or_socket, auth_secret =
auth_secret)
- self.server.connect(self)
+ def __init__(self):
+ self.status = DISCONNECTED
+ self.server = None
self._channels_list = []
self.signals = {
@@ -68,9 +67,18 @@
self._channels_by_tuner_id = {}
self._channels_list = []
- self.server.signals['closed'].connect_weak(self._handle_disconnected)
+ def connect(self, server_or_socket, auth_secret = ''):
+ """
+ Connect to EPG server.
+ """
+ self.status = CONNECTING
+ self.server = kaa.rpc.Client(server_or_socket, auth_secret =
auth_secret)
+ self.server.connect(self)
+ self.server.signals['closed'].connect_weak(self._handle_disconnected)
+
+
def _handle_disconnected(self):
"""
Signal callback when server disconnects.
@@ -78,7 +86,7 @@
log.debug('kaa.epg client disconnected')
self.status = DISCONNECTED
self.signals["disconnected"].emit()
- del self.server
+ self.server = None
@kaa.rpc.expose('guide.update')
@@ -117,31 +125,16 @@
self.signals["updated"].emit()
- def _program_rows_to_objects(self, query_data, callback=None):
- """
- Convert raw search result data from the server into python objects.
- """
- results = []
- channel = None
- for row in query_data:
- if not channel or row['parent_id'] != channel.db_id:
- if row['parent_id'] not in self._channels_by_db_id:
- continue
- channel = self._channels_by_db_id[row['parent_id']]
- results.append(Program(channel, row))
- if callback:
- callback(results)
- return results
-
-
- def search(self, callback=None, channel=None, time=None, **kwargs):
+ @kaa.notifier.yield_execution()
+ def search(self, channel=None, time=None, **kwargs):
"""
Search the db. This will call the search function on server side using
- kaa.ipc. Notice: this will call kaa.notifier.step() until the result
- arrives.
+ kaa.ipc. This function will return an InProgress object.
"""
if self.status == DISCONNECTED:
- return []
+ # make sure we always return InProgress
+ yield kaa.notifier.YieldContinue
+ yield []
if channel is not None:
if isinstance(channel, Channel):
@@ -162,14 +155,29 @@
kwargs["start"] = kaa.db.QExpr("range", (int(start) - max,
int(stop)))
kwargs["stop"] = kaa.db.QExpr(">=", int(start))
- in_progress = self.server.rpc('guide.query', type='program', **kwargs)
- if callback:
- in_progress.connect(self._program_rows_to_objects, callback)
- return None
- # ugly!!!!!
- while not in_progress.is_finished:
- kaa.notifier.step()
- return self._program_rows_to_objects(in_progress())
+ query_data = self.server.rpc('guide.query', type='program', **kwargs)
+ # wait for the rpc to finish
+ yield query_data
+ # get data
+ query_data = query_data()
+
+ # Convert raw search result data
+ if kwargs.get('attrs'):
+ attrs = kwargs.get('attrs')
+ def combine_attrs(row):
+ return [ row.get(a) for a in attrs ]
+ yield [ combine_attrs(row) for row in query_data ]
+
+ # Convert raw search result data from the server into python objects.
+ results = []
+ channel = None
+ for row in query_data:
+ if not channel or row['parent_id'] != channel.db_id:
+ if row['parent_id'] not in self._channels_by_db_id:
+ continue
+ channel = self._channels_by_db_id[row['parent_id']]
+ results.append(Program(channel, row))
+ yield results
def new_channel(self, tuner_id=None, name=None, long_name=None):
Modified: trunk/epg/src/server.py
==============================================================================
--- trunk/epg/src/server.py (original)
+++ trunk/epg/src/server.py Sun Feb 25 12:20:30 2007
@@ -69,7 +69,7 @@
stop = (int, ATTR_SEARCHABLE),
episode = (unicode, ATTR_SIMPLE),
subtitle = (unicode, ATTR_SIMPLE),
- genre = (unicode, ATTR_SIMPLE),
+ genre = (unicode, ATTR_SEARCHABLE),
date = (int, ATTR_SEARCHABLE),
rating = (dict, ATTR_SIMPLE)
)
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog