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`.
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)))
"""
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:
from ..command import Command, Argument, Failure
from ..curve import NotRecognized
-from ..playlist import FilePlaylist
+from ..playlist import load
from ..util.itertools import reverse_enumerate
from . import Builtin
help=self.__doc__, plugin=plugin)
def _run(self, hooke, inqueue, outqueue, params):
- p = FilePlaylist(drivers=params['drivers'], path=params['input'])
- p.load(hooke=hooke)
+ p = load(path=params['input'], drivers=params['drivers'])
self._set_playlist(hooke, params, p)
outqueue.put(p)