1 """Defines :class:`PlaylistPlugin` several associated
2 :class:`hooke.plugin.Command`\s for handling :mod:`hooke.playlist`
8 from ..playlist import FilePlaylist
9 from ..plugin import Builtin, Command, Argument
12 class PlaylistPlugin (Builtin):
14 super(PlaylistPlugin, self).__init__(name='playlist')
17 return [NextCommand(), PreviousCommand(), JumpCommand(),
18 SaveCommand(), LoadCommand(),
19 AddCommand(), AddGlobCommand(),
20 RemoveCommand(), FilterCommand()]
22 class NextCommand (Command):
23 """Move playlist to the next curve.
26 super(NextCommand, self).__init__(
29 Argument(name='playlist', type='playlist', optional=False,
31 :class:``hooke.plugin.playlist.Playlist`` to act on.
36 def _run(inqueue, outqueue, params):
37 params['playlist'].next()
39 class PreviousCommand (Command):
40 """Move playlist to the previous curve.
43 super(PreviousCommand, self).__init__(
44 name='previous curve',
46 Argument(name='playlist', type='playlist', optional=False,
48 :class:``hooke.plugin.playlist.Playlist`` to act on.
53 def _run(inqueue, outqueue, params):
54 params['playlist'].previous()
56 class JumpCommand (Command):
57 """Move playlist to a given curve.
60 super(JumpCommand, self).__init__(
63 Argument(name='playlist', type='playlist', optional=False,
65 :class:``hooke.plugin.playlist.Playlist`` to act on.
67 Argument(name='index', type='int', optional=False, help="""
68 Index of target curve.
73 def _run(inqueue, outqueue, params):
74 params['playlist'].jump(params['index'])
76 class SaveCommand (Command):
80 super(SaveCommand, self).__init__(
83 Argument(name='playlist', type='playlist', optional=False,
85 :class:``hooke.plugin.playlist.Playlist`` to act on.
87 Argument(name='output', type='file',
89 File name for the output playlist. Defaults to overwring the input
95 def _run(inqueue, outqueue, params):
96 params['playlist'].save(params['output'])
98 class LoadCommand (Command):
102 super(LoadCommand, self).__init__(
103 name='load playlist',
105 Argument(name='input', type='file', optional=False,
107 File name for the input playlist.
109 Argument(name='digests', type='digest', optional=False,
112 Digests for loading curves.
117 def _run(inqueue, outqueue, params):
118 p = FilePlaylist(drivers=params['drivers'], path=params['input'])
122 class AddCommand (Command):
123 """Add a curve to a playlist.
126 super(AddCommand, self).__init__(
127 name='add curve to playlist',
129 Argument(name='playlist', type='playlist', optional=False,
131 :class:``hooke.plugin.playlist.Playlist`` to act on.
133 Argument(name='input', type='file', optional=False,
135 File name for the input :class:`hooke.curve.Curve`.
137 Argument(name='info', type='dict', optional=True,
139 Additional information for the input :class:`hooke.curve.Curve`.
144 def _run(inqueue, outqueue, params):
145 params['playlist'].append_curve_by_path(params['input'],
148 class AddGlobCommand (Command):
149 """Add curves to a playlist with file globbing.
151 Adding lots of files one at a time can be tedious. With this
152 command you can use globs (`data/curves/*.dat`) to add curves
153 for all matching files at once.
156 super(AddCommand, self).__init__(
157 name='glob curves to playlist',
159 Argument(name='playlist', type='playlist', optional=False,
161 :class:``hooke.plugin.playlist.Playlist`` to act on.
163 Argument(name='input', type='glob', optional=False,
165 File name glob for the input :class:`hooke.curve.Curve`.
167 Argument(name='info', type='dict', optional=True,
169 Additional information for the input :class:`hooke.curve.Curve`.
174 def _run(inqueue, outqueue, params):
175 for path in sorted(glob.glob(params['input'])):
176 params['playlist'].append_curve_by_path(path, params['info'])
178 class RemoveCommand (Command):
179 """Remove a curve from a playlist.
182 super(RemoveCommand, self).__init__(
183 name='remove curve from playlist',
185 Argument(name='playlist', type='playlist', optional=False,
187 :class:``hooke.plugin.playlist.Playlist`` to act on.
189 Argument(name='index', type='int', optional=False, help="""
190 Index of target curve.
195 def _run(inqueue, outqueue, params):
196 params['playlist'].pop(params['index'])
197 params['playlist'].jump(params._index)
199 class FilterCommand (Command):
200 """Create a subset playlist via a selection function.
202 Removing lots of curves one at a time can be tedious. With this
203 command you can use a function `filter` to select the curves you
207 super(FilterCommand, self).__init__(
208 name='filter playlist',
210 Argument(name='playlist', type='playlist', optional=False,
212 :class:``hooke.plugin.playlist.Playlist`` to act on.
214 Argument(name='filter', type='function', optional=False,
216 Function returning `True` for "good" curves. `filter(curve) -> True/False`.
221 def _run(inqueue, outqueue, params):
222 p = params['playlist'].filter(params['filter'])