Cleaned up hooke.playlist.load() and its use in `load playlist`.
[hooke.git] / hooke / playlist.py
index fd7ac4bf81107795bb3811f2ee36877b6b7b17c4..a4dd0abcf525858587c8e6bb24d4020fb0c20554 100644 (file)
@@ -201,6 +201,24 @@ class Playlist (NoteIndexList):
                 oldest = self._loaded.pop(0)
                 oldest.unload()
 
+def playlist_path(path):
+    """Normalize playlist path extensions.
+
+    Examples
+    --------
+    >>> print playlist_path('playlist')
+    playlist.hkp
+    >>> print playlist_path('playlist.hkp')
+    playlist.hkp
+    >>> print playlist_path(None)
+    None
+    """
+    if path == None:
+        return None
+    if not path.endswith('.hkp'):
+        path += '.hkp'
+    return path
+
 
 class FilePlaylist (Playlist):
     """A file-backed :class:`Playlist`.
@@ -272,8 +290,7 @@ class FilePlaylist (Playlist):
             if self._base_path == None:
                 self._base_path = os.getcwd()
         else:
-            if not path.endswith('.hkp'):
-                path += '.hkp'
+            path = playlist_path(path)
             self.path = path
             self._base_path = os.path.dirname(os.path.abspath(
                 os.path.expanduser(self.path)))
@@ -537,13 +554,19 @@ def from_string(string):
     """
     return yaml.load(string)
 
-def load(path=None, identify=True, hooke=None):
+def load(path=None, drivers=None, identify=True, hooke=None):
     """Load a playlist from a file.
     """
-    with open(self.path, 'r') as f:
+    path = playlist_path(path)
+    with open(path, 'r') as f:
         text = f.read()
     playlist = from_string(text)
+    playlist.set_path(path)
+    print type(playlist)
     playlist._digest = playlist.digest()
+    if drivers != None:
+        playlist.drivers = drivers
+    playlist.set_path(path)
     for curve in playlist:
         curve.set_hooke(hooke)
         if identify == True: