Standardize playlist path expansion in hooke/playlist.py.
authorW. Trevor King <wking@drexel.edu>
Wed, 9 Nov 2011 19:55:10 +0000 (14:55 -0500)
committerW. Trevor King <wking@drexel.edu>
Wed, 9 Nov 2011 19:55:10 +0000 (14:55 -0500)
hooke/playlist.py

index c89298e67a486fe355f3db59636e2f5a289e49ab..f323ca2b099043875c384e9fcd4831d4288cd495 100644 (file)
@@ -213,7 +213,7 @@ class Playlist (NoteIndexList):
             pass
 
 
-def playlist_path(path):
+def playlist_path(path, expand=False):
     """Normalize playlist path extensions.
 
     Examples
@@ -229,6 +229,8 @@ def playlist_path(path):
         return None
     if not path.endswith('.hkp'):
         path += '.hkp'
+    if expand:
+        path = os.path.abspath(os.path.expanduser(path))
     return path
 
 
@@ -302,10 +304,9 @@ class FilePlaylist (Playlist):
             if self._base_path == None:
                 self._base_path = os.getcwd()
         else:
-            path = playlist_path(path)
+            path = playlist_path(path, expand=True)
             self.path = path
-            self._base_path = os.path.dirname(os.path.abspath(
-                os.path.expanduser(self.path)))
+            self._base_path = os.path.dirname(self.path)
             if self.name == None:
                 self.name = os.path.basename(path)
         if self._base_path != orig_base_path:
@@ -575,7 +576,7 @@ def from_string(string):
 def load(path=None, drivers=None, identify=True, hooke=None):
     """Load a playlist from a file.
     """
-    path = os.path.expanduser(playlist_path(path))
+    path = playlist_path(path, expand=True)
     with open(path, 'r') as f:
         text = f.read()
     playlist = from_string(text)