1 """Defines :class:`PlaylistPlugin` several associated
2 :class:`hooke.plugin.Command`\s for handling :mod:`hooke.playlist`
8 from ..command import Command, Argument
9 from ..playlist import FilePlaylist
10 from ..plugin import Builtin
13 class PlaylistPlugin (Builtin):
15 super(PlaylistPlugin, self).__init__(name='playlist')
18 return [NextCommand(), PreviousCommand(), JumpCommand(),
19 SaveCommand(), LoadCommand(),
20 AddCommand(), AddGlobCommand(),
21 RemoveCommand(), FilterCommand()]
23 class NextCommand (Command):
24 """Move playlist to the next curve.
27 super(NextCommand, self).__init__(
30 Argument(name='playlist', type='playlist', optional=False,
32 :class:`hooke.plugin.playlist.Playlist` to act on.
37 def _run(inqueue, outqueue, params):
38 params['playlist'].next()
40 class PreviousCommand (Command):
41 """Move playlist to the previous curve.
44 super(PreviousCommand, self).__init__(
45 name='previous curve',
47 Argument(name='playlist', type='playlist', optional=False,
49 :class:`hooke.plugin.playlist.Playlist` to act on.
54 def _run(inqueue, outqueue, params):
55 params['playlist'].previous()
57 class JumpCommand (Command):
58 """Move playlist to a given curve.
61 super(JumpCommand, self).__init__(
64 Argument(name='playlist', type='playlist', optional=False,
66 :class:`hooke.plugin.playlist.Playlist` to act on.
68 Argument(name='index', type='int', optional=False, help="""
69 Index of target curve.
74 def _run(inqueue, outqueue, params):
75 params['playlist'].jump(params['index'])
77 class SaveCommand (Command):
81 super(SaveCommand, self).__init__(
84 Argument(name='playlist', type='playlist', optional=False,
86 :class:`hooke.plugin.playlist.Playlist` to act on.
88 Argument(name='output', type='file',
90 File name for the output playlist. Defaults to overwring the input
96 def _run(inqueue, outqueue, params):
97 params['playlist'].save(params['output'])
99 class LoadCommand (Command):
103 super(LoadCommand, self).__init__(
104 name='load playlist',
106 Argument(name='input', type='file', optional=False,
108 File name for the input playlist.
110 Argument(name='digests', type='digest', optional=False,
113 Digests for loading curves.
118 def _run(inqueue, outqueue, params):
119 p = FilePlaylist(drivers=params['drivers'], path=params['input'])
123 class AddCommand (Command):
124 """Add a curve to a playlist.
127 super(AddCommand, self).__init__(
128 name='add curve to playlist',
130 Argument(name='playlist', type='playlist', optional=False,
132 :class:`hooke.plugin.playlist.Playlist` to act on.
134 Argument(name='input', type='file', optional=False,
136 File name for the input :class:`hooke.curve.Curve`.
138 Argument(name='info', type='dict', optional=True,
140 Additional information for the input :class:`hooke.curve.Curve`.
145 def _run(inqueue, outqueue, params):
146 params['playlist'].append_curve_by_path(params['input'],
149 class AddGlobCommand (Command):
150 """Add curves to a playlist with file globbing.
152 Adding lots of files one at a time can be tedious. With this
153 command you can use globs (`data/curves/*.dat`) to add curves
154 for all matching files at once.
157 super(AddGlobCommand, self).__init__(
158 name='glob curves to playlist',
160 Argument(name='playlist', type='playlist', optional=False,
162 :class:`hooke.plugin.playlist.Playlist` to act on.
164 Argument(name='input', type='glob', optional=False,
166 File name glob for the input :class:`hooke.curve.Curve`.
168 Argument(name='info', type='dict', optional=True,
170 Additional information for the input :class:`hooke.curve.Curve`.
175 def _run(inqueue, outqueue, params):
176 for path in sorted(glob.glob(params['input'])):
177 params['playlist'].append_curve_by_path(path, params['info'])
179 class RemoveCommand (Command):
180 """Remove a curve from a playlist.
183 super(RemoveCommand, self).__init__(
184 name='remove curve from playlist',
186 Argument(name='playlist', type='playlist', optional=False,
188 :class:`hooke.plugin.playlist.Playlist` to act on.
190 Argument(name='index', type='int', optional=False, help="""
191 Index of target curve.
196 def _run(inqueue, outqueue, params):
197 params['playlist'].pop(params['index'])
198 params['playlist'].jump(params._index)
200 class FilterCommand (Command):
201 """Create a subset playlist via a selection function.
203 Removing lots of curves one at a time can be tedious. With this
204 command you can use a function `filter` to select the curves you
208 super(FilterCommand, self).__init__(
209 name='filter playlist',
211 Argument(name='playlist', type='playlist', optional=False,
213 :class:`hooke.plugin.playlist.Playlist` to act on.
215 Argument(name='filter', type='function', optional=False,
217 Function returning `True` for "good" curves. `filter(curve) -> True/False`.
222 def _run(inqueue, outqueue, params):
223 p = params['playlist'].filter(params['filter'])