Merge branches 'master' and 'playlist' playlist
authorAndre L. V. Loureiro <loureiro.andrew@gmail.com>
Thu, 21 May 2009 01:56:33 +0000 (21:56 -0400)
committerAndre L. V. Loureiro <loureiro.andrew@gmail.com>
Thu, 21 May 2009 01:56:33 +0000 (21:56 -0400)
Conflicts:
zukebox_server/src/playlist/zukebox_playlist.py
Merged

1  2 
zukebox_server/src/playlist/zukebox_playlist.py

  
--import dbus.service
+ import os
  
  from brisa.core import log
+ from brisa.upnp.device import Service, ServiceController
  
- class PlayList(list, dbus.service.Object):
+ pjoin = os.path.join
+ class PlayListOutBoundExcept(Exception):
+     def __rep__(self):
+         return "Play List Out of Bounds!"
+ class PlayList(Service):
      """Class PlayList
      Introduction
      ============
      Implements a playlist for ZukeBox server.
      """
  
-     DBUS_SERVICE_NAME = "br.org.zagaia.PlayList"
-     DBUS_OBJ_PATH = "br/org/zagaia/playlist"
-     DBUS_IFACE = "br.org.zagaia.PlayList"
+     service_type = "urn:schemas-upnp-org:service:PlayList:1"
+     service_name = "PlayList"
+     def __init__(self, positions=10, xml_path):
+         scpd_path = pjoin(xml_path, "zukebox-playlist-scpd.xml")
+         Service.__init__(self, service_name, service_type, '', scpd_path,
+                 PlayListControl(positions, service_type))
  
-     def __init__(self, name="", positions=10):
-         self.name = name
+     def get_playlist(self):
+         return self.control_controller.get_playlist()
+ class PlayListControl(ServiceController):
+     def __init__(self, positions, serv_type):
+         ServiceController.__init__(self, serv_type)
          self.positions = positions
+         self.list = []
+         self.current = 0
+         self.prev = self.current
+         self.next = None
+         self.from_name = None
+         self.to_name = None
+         self.current_uri = None
+         self.current_uri_metadata = None
  
-     def is_locked(self):
-         if not len(self) == self.positions:
-             return False
-         return True
+     def soap_IsLocked(self, *args, **kwargs):
+         locked = True
+         if not len(self.list) == self.positions:
+             locked = False
+         rt = {"Locked": locked}
+         return {"IsLockedResponse": rt}
  
-     def is_availble(self):
-         if not len(self) == 0:
-             return True
-         return False
+     def soap_IsAvailble(self, *args, **kwargs):
+         availble = False
+         if not len(self.list) == 0:
+             availble = True
+         rt = {"Availble": availble}
+         return {"IsAvailbleResponse": rt}
  
-     @dbus.service.method(DBUS_IFACE)
-     def append(self, obj):
-         """Put a object in the playlist"""
+     def soap_Append(self, *args, **kwargs):
+         """Put a object in the playlist
+         """
          if not self.is_locked():
-             log.info("object in playlist")
-             self.append(obj)
+             self.current_uri = kwargs["CurrentURI"]
+             self.current_uri_metadata = kwargs["CurrentURIMetaData"]
+             self.from_name = kwargs["FromName"]
+             self.to_name = kwargs["ToName"]
+             self.list.append(self.current_uri)
  
-     @dbus.service.method(DBUS_IFACE)
-     def drop(self):
-         """Always pop the first object from list"""
+             return {"Append": {}}
+         else:
+             raise PlayListOutBoundExcept()
+     def soap_Drop(self, *args, **kwargs):
+         """Pop the object at position passed by index
+         """
          if self.is_availble():
-             self.pop(0)
+             index = kwargs["Index"]
+             self.list.pop(index)
+             return {"Drop": {}}
+         else:
+             raise PlayListOutBoundExcept()
  
-     @dbus.service.method(DBUS_IFACE)
-     def get_size(self):
+     def soap_GetSizeOfPlayList(self, *args, **kwargs):
          """Return the size of playlist"""
-         return len(self)
+         lenght = len(self.list)
+         rt = {"PlayListSize": lenght}
+         return {"GetSizeOfPlayListResponse": rt}
  
-     @dbus.service.method(DBUS_IFACE)
-     def previous(self):
+     def soap_GetCurrent(self, *args, **kwargs):
          if self.is_availble():
-             pass
+             rt = {"CurrentPosition": self.list[self.current]}
+             return {"GetCurrentResponse": rt}
  
+     def clean_playlist(self):
+         if self.is_availble():
+             self.list = []
  
+     def get_playlist(self):
+         return self.list
 -