From: W. Trevor King Date: Sun, 22 Aug 2010 05:03:28 +0000 (-0400) Subject: Cleaned up hooke.playlist.load() and its use in `load playlist`. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=db6a80574c9e8d7a329d184494442f86cfc6118a;p=hooke.git Cleaned up hooke.playlist.load() and its use in `load playlist`. --- diff --git a/hooke/playlist.py b/hooke/playlist.py index fd7ac4b..a4dd0ab 100644 --- a/hooke/playlist.py +++ b/hooke/playlist.py @@ -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: diff --git a/hooke/plugin/playlist.py b/hooke/plugin/playlist.py index 3b1d837..3699301 100644 --- a/hooke/plugin/playlist.py +++ b/hooke/plugin/playlist.py @@ -27,7 +27,7 @@ import os.path 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 @@ -250,8 +250,7 @@ Drivers for loading curves. 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)