096ca0d9f87b — Oben Sonne 10 years ago
server: various fixes in the bong player
1 files changed, 9 insertions(+), 6 deletions(-)

M server/src/tests/bong.py
M server/src/tests/bong.py +9 -6
@@ 39,6 39,7 @@ class Bong(dbus.service.Object):
         with open(fname) as fp:
             self.x = yaml.load(fp)
         self.fname = fname
+        log('initial state: %s' % self.x)
 
         watchfile(fname, self.onstatechange)
 

          
@@ 46,7 47,6 @@ class Bong(dbus.service.Object):
         log("new content: %r" % content)
         x = yaml.load(content)
         for k, v in x.items():
-            log('check %s, %s' % (k, v))
             if k.startswith("info_"):
                 continue
             if self.x.get(k, None) != v:  # FIXME: fails on playlist changes

          
@@ 62,10 62,13 @@ class Bong(dbus.service.Object):
                 v = v if isinstance(v, list) else [v]
                 getattr(self, signal)(*v)
             else:
-                log('no change')
+                log('%s did not change (%s)' % (k, v))
 
     def changestate(self, field, value):
-        x = self.x.copy()
+        """Change the player's state (offline/infile only)."""
+        log('change %s to %s' % (field, value))
+        with open(self.fname, 'r') as fp:
+            x = yaml.load(fp)
         x[field] = value
         with open(self.fname, 'w') as fp:
             yaml.dump(x, fp)

          
@@ 200,14 203,14 @@ class Bong(dbus.service.Object):
 
     @dbus.service.method(IFACE, 's', '')
     def SetRepeat(self, mode):
-        if mode not in self.features['repeatmodes']:
+        if mode not in self.x.get('info_repeatmodes', []):
             raise PlayerException("invalid repeat mode")
         self.changestate('repeat', mode)
 
     @dbus.service.method(IFACE, 's', '')
     def SetShuffle(self, mode):
-        if mode not in self.features['shufflemodes']:
-            raise PlayerException("invalid repeat mode")
+        if mode not in self.x.get('info_shufflemodes', []):
+            raise PlayerException("invalid shuffle mode")
         self.changestate('shuffle', mode)
 
     @dbus.service.method(IFACE, 'u', '')