Author: dmeyer
Date: Thu Mar 23 19:34:25 2006
New Revision: 8133

Modified:
   trunk/tvserver/src/epg.py
   trunk/tvserver/src/server.py

Log:
make it possible to start update over mbus

Modified: trunk/tvserver/src/epg.py
==============================================================================
--- trunk/tvserver/src/epg.py   (original)
+++ trunk/tvserver/src/epg.py   Thu Mar 23 19:34:25 2006
@@ -2,7 +2,7 @@
 # -----------------------------------------------------------------------------
 # epg.py - EPG handling for the recordserver
 # -----------------------------------------------------------------------------
-# $Id: server.py 7893 2006-01-29 17:53:54Z dmeyer $
+# $Id$
 #
 #
 # -----------------------------------------------------------------------------
@@ -53,7 +53,11 @@
 class EPG(object):
 
     def __init__(self):
-        self.signals = { 'changed': Signal() }
+        self.signals = {
+            'changed': Signal(),
+            'updated': Signal()
+            }
+        self.updating = False
 
 
     def channels(self):
@@ -110,7 +114,7 @@
         if not channel:
             log.error('unable to find %s in epg database', rec.channel)
             return True
-            
+
         # try to find the exact title again
         results = kaa.epg.search(title = rec.name, channel=channel, time = 
interval)
 
@@ -135,7 +139,7 @@
                 log.info('unable to find recording in epg:\n%s' % rec)
                 return True
 
-        # check if attributes changed 
+        # check if attributes changed
         for attr in ('description', 'episode', 'subtitle'):
             newattr = getattr(epginfo, attr)
             oldattr = getattr(rec, attr)
@@ -210,56 +214,37 @@
         return True
 
 
+    def update(self):
+        """
+        Update the epg data in the epg server
+        """
+        if self.updating:
+            return False
 
-def update():
-    """
-    Update epg data.
-    """
-    def update_progress(cur, total):
-        n = 0
-        if total > 0:
-            n = int((cur / float(total)) * 50)
-        sys.stdout.write("|%51s| %d / %d\r" % (("="*n + ">").ljust(51), cur, 
total))
-        sys.stdout.flush()
-        if cur == total:
-            print
-
-    guide = kaa.epg.guide
-
-    guide.signals["update_progress"].connect(update_progress)
-    guide.signals["updated"].connect(sys.exit)
-
-    if config.epg.xmltv.activate == 1:
-
-        if not config.epg.xmltv.data_file:
-            log.error('XMLTV gabber not supported yet. Please download the')
-            log.error('file manually and set epg.xmltv.data_file')
-        else:
+        self.updating = True
+        sources = kaa.epg.sources.items()[:]
+        sources.sort(lambda x,y: cmp(x[0], y[0]))
+        kaa.epg.guide.signals["updated"].connect(self.update_step, sources)
+        self.update_step(sources)
+        return True
 
-            data_file = str(config.epg.xmltv.data_file)
-            log.info('loading data into EPG...')
-            guide.update("xmltv", data_file)
-            
-    else:
-        print 'not configured to use xmltv'
-
-
-    if config.epg.zap2it.activate == 1:
-        guide.update("zap2it", username=str(config.epg.zap2it.username), 
-                               passwd=str(config.epg.zap2it.password))
-
-    else:
-        print 'not configured to use Zap2it'
-
-
-    if config.epg.vdr.activate == 1:
-        print 'update epg based on vdr data'
-        guide.update("vdr", vdr_dir=str(config.epg.vdr.dir), 
-                     channels_file=str(config.epg.vdr.channels_file), 
-                     epg_file=str(config.epg.vdr.epg_file),
-                     host=str(config.epg.vdr.host), 
port=int(config.epg.vdr.port), 
-                     access_by=str(config.epg.vdr.access_by), 
-                     limit_channels=str(config.epg.vdr.limit_channels))
 
-    else:
-        print 'not configured to use VDR'
+    def update_step(self, sources):
+        """
+        Update the next source in the sources list
+        """
+        if not sources:
+            log.info('epg update complete')
+            kaa.epg.guide.signals["updated"].disconnect(self.update_step)
+            self.updating = True
+            self.signals['updated'].emit()
+            return True
+
+        name, module = sources.pop(0)
+        if not module.config.activate:
+            log.info('skip epg update on %s', name)
+            return self.update_step(sources)
+
+        log.info('start epg update on %s', name)
+        kaa.epg.guide.update(name)
+        return True

Modified: trunk/tvserver/src/server.py
==============================================================================
--- trunk/tvserver/src/server.py        (original)
+++ trunk/tvserver/src/server.py        Thu Mar 23 19:34:25 2006
@@ -68,7 +68,8 @@
     def __init__(self):
         self.scheduler = Scheduler(self.scheduler_callback)
         self.epg = EPG()
-
+        self.epg.signals['updated'].connect(self.epg_update)
+        
         self.last_listing = []
         self.live_tv_map = {}
         self.locked = False
@@ -577,6 +578,11 @@
         return ret
 
 
+    #
+    # home.theatre.epg rpc commands
+    #
+
+
     @freevo.ipc.expose('home-theatre.epg.connect')
     def rpc_epg_connect(self):
         """
@@ -584,13 +590,21 @@
         return self.epgaddr
 
 
+    @freevo.ipc.expose('home-theatre.epg.update')
+    def rpc_epg_update(self):
+        """
+        """
+        self.epg.update()
+        return []
+
+
     #
     # mbus.status handling
     #
 
     def update_status(self):
         """
-        Update status information evenry minute.
+        Update status information every minute.
         """
         ctime = time.time()
 
@@ -604,7 +618,10 @@
             # something is recording, add busy time of first recording
             busy = rec[0].stop + rec[0].stop_padding - ctime
             self.status.set('busy', max(1, int(busy / 60) + 1))
-
+        elif self.epg.updating:
+            # epg update in progress
+            self.status.set('busy', 1)
+            
         # find next scheduled recordings for wakeup
         # FIXME: what about CONFLICT? we don't need to start the server
         # for a normal conflict, but we may need it when tvdev is not running


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to