Author: dmeyer
Date: Thu Aug 30 13:44:23 2007
New Revision: 9850

Log:
Part 1 of a patch from Tanja:
o add favorite modify to core
o change times handling in TVSserver Favorite
o small core interface changes


Modified:
   trunk/core/src/ipc/tvserver.py
   trunk/tvserver/src/favorite.py
   trunk/tvserver/src/server.py

Modified: trunk/core/src/ipc/tvserver.py
==============================================================================
--- trunk/core/src/ipc/tvserver.py      (original)
+++ trunk/core/src/ipc/tvserver.py      Thu Aug 30 13:44:23 2007
@@ -266,7 +266,7 @@
             info['subtitle'] = prog.subtitle
 
         result = self.rpc('home-theatre.recording.add', prog.title,
-                          prog.channel.name, 1000, prog.start, prog.stop, info)
+                          prog.channel, 1000, prog.start, prog.stop, info)
         yield result
         if not result():
             # FIXME: get real error message from tvserver
@@ -291,7 +291,7 @@
     """
     A favorite object from the recordserver.
     """
-    def __init__(self, id, title, channels, priority, days, time, one_shot,
+    def __init__(self, id, title, channels, priority, days, times, one_shot,
                  substring):
         """
         The init function creates the object. The parameters are the complete
@@ -302,7 +302,7 @@
         self.channels = channels
         self.priority = priority
         self.days = days
-        self.time = time
+        self.times = times
         self.one_shot = one_shot
         self.substring = substring
         self.description = {}
@@ -414,6 +414,33 @@
         yield self.SUCCESS
 
 
+    @kaa.notifier.yield_execution()
+    def modify(self, id, info):
+        """
+        remove a favorite
+        parameter: id of the favorite,
+                   info of the changed item [ ( var, val ) (...) ]
+        """
+        if not self.server:
+            yield _('tvserver unavailable')
+        result = self.rpc('home-theatre.favorite.modify', id, info)
+        yield result
+        if not result():
+            # FIXME: get real error message from tvserver
+            yield 'failed'
+        yield self.SUCCESS
+
+
+    def get(self, title, channel, start, stop):
+        for f in self.list():
+            if title == f.title:
+                if channel in f.channels:
+                    day = min(time.localtime(start)[6] + 1, 6)
+                    if day in f.days:
+                        return f
+        return None    
+    
+    
     def list(self):
         """
         """

Modified: trunk/tvserver/src/favorite.py
==============================================================================
--- trunk/tvserver/src/favorite.py      (original)
+++ trunk/tvserver/src/favorite.py      Thu Aug 30 13:44:23 2007
@@ -81,16 +81,11 @@
         self.channels  = channels
         self.priority  = priority
         self.days      = days
-        self.times     = []
         self.url       = ''
         self.fxdname   = ''
         self.once      = once
         self.substring = substring
-        for t in times:
-            m = _time_re.match(t).groups()
-            start = int(m[0])*100 + int(m[1])
-            stop  = int(m[2])*100 + int(m[3])
-            self.times.append((start, stop))
+        self.times     = times
         self.start_padding = config.record.start_padding
         self.stop_padding  = config.record.stop_padding
 
@@ -119,10 +114,7 @@
             if child.name == 'times':
                 self.times = []
                 for t in child.children:
-                    m = _time_re.match(t.content).groups()
-                    start = int(m[0])*100 + int(m[1])
-                    stop  = int(m[2])*100 + int(m[3])
-                    self.times.append((start, stop))
+                    self.times.append(t.content)
             if child.name == 'padding':
                 self.start_padding = int(child.getattr('start'))
                 self.stop_padding  = int(child.getattr('stop'))
@@ -159,8 +151,11 @@
         if not int(time.strftime('%w', timestruct)) in self.days:
             return False
         stime = int(timestruct[3]) * 100 + int(timestruct[4])
-        for t1, t2 in self.times:
-            if stime >= t1 and stime <= t2:
+        for t in self.times:
+            m = _time_re.match(t).groups()
+            start = int(m[0])*100 + int(m[1])
+            stop  = int(m[2])*100 + int(m[3])
+            if stime >= start and stime <= stop:
                 return True
         return False
 
@@ -252,8 +247,7 @@
             channels.add_child('channel', chan)
         times = node.add_child('times')
         for t in self.times:
-            times.add_child('start', '%02d:%02d-%02d:%02d' % \
-                            (t[0] / 100, t[0] % 100, t[1] / 100, t[1] % 100))
+            times.add_child('start', t)
         if self.once:
             node.add_child('once')
         if self.substring:

Modified: trunk/tvserver/src/server.py
==============================================================================
--- trunk/tvserver/src/server.py        (original)
+++ trunk/tvserver/src/server.py        Thu Aug 30 13:44:23 2007
@@ -433,10 +433,10 @@
 
 
     @freevo.ipc.expose('home-theatre.recording.modify')
-    def rpc_recording_modify(self, int, info):
+    def rpc_recording_modify(self, id, info):
         """
         modify a recording
-        parameter: id [ ( var val ) (...) ]
+        parameter: id, [ ( var, val ) (...) ]
         """
         key_val = dict(info)
         log.info('recording.modify: %s' % id)
@@ -564,6 +564,12 @@
             return NameError('Already scheduled')
         self.favorites.append(f)
 
+        # Align favorites id(s)
+        next = 0
+        for r in self.favorites:
+            r.id = next
+            next += 1
+
         # update schedule
         self.epg_update()
         
@@ -586,6 +592,12 @@
             return NameError('Favorite not found!')
         log.info('favorite.remove: %s', f)
         self.favorites.remove(f)
+        
+        # Align favorites id(s)
+        next = 0
+        for r in self.favorites:
+            r.id = next
+            next += 1
 
         # send update to all clients
         msg = [ f.long_list() for f in self.favorites ]
@@ -593,6 +605,29 @@
         return []
 
 
+    @freevo.ipc.expose('home-theatre.favorite.modify')
+    def rpc_favorite_modify(self, id, info):
+        """
+        modify a recording
+        parameter: id, [ ( var, val ) (...) ]
+        """
+        key_val = dict(info)
+        log.info('favorite.modify: %s' % id)
+        for r in self.favorites:
+            if r.id == id:
+                cp = copy.copy(self.favorites[id])
+                for key in key_val:
+                    setattr(cp, key, key_val[key])
+                self.favorites[self.favorites.index(r)] = cp
+                # update schedule
+                self.epg_update()
+                # send update to all clients
+                msg = [ f.long_list() for f in self.favorites ]
+                self.send_event('home-theatre.favorite.list.update', *msg)
+                return []
+        return IndexError('Favorite not found')
+
+
     @freevo.ipc.expose('home-theatre.favorite.list')
     def rpc_favorite_list(self):
         """

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to