The playlist module provides a Playlist and its subclass FilePlaylist for manipulating lists of hooke.curve.Curves.
A file-backed Playlist.
Examples
>>> p = FilePlaylist(drivers=['Driver A', 'Driver B'])
>>> p.append(Curve('dummy/path/A'))
>>> p.append(Curve('dummy/path/B'))
The data-type is pickleable, to ensure we can move it between processes with multiprocessing.Queues.
>>> import pickle
>>> s = pickle.dumps(p)
>>> z = pickle.loads(s)
>>> for curve in z:
... print curve
<Curve A>
<Curve B>
>>> print z.drivers
['Driver A', 'Driver B']
The data-type is also YAMLable (see hooke.util.yaml).
>>> s = yaml.dump(p)
>>> z = yaml.load(s)
>>> for curve in z:
... print curve
<Curve A>
<Curve B>
>>> print z.drivers
['Driver A', 'Driver B']
Methods
append | |
append_curve | |
append_curve_by_path | |
count | |
current | |
digest | |
extend | |
filter | |
flatten | |
index | |
insert | |
is_saved | |
items | |
jump | |
next | |
pop | |
previous | |
remove | |
reverse | |
save | |
set_path | |
sort | |
unload | |
update_curve_paths |
Compute the sha1 digest of the flattened playlist representation.
Examples
>>> root_path = os.path.sep + 'path'
>>> p = FilePlaylist(drivers=[],
... path=os.path.join(root_path, 'to','playlist'))
>>> p.info['note'] = 'An example playlist'
>>> c = Curve(os.path.join(root_path, 'to', 'curve', 'one'))
>>> c.info['note'] = 'The first curve'
>>> p.append_curve(c)
>>> c = Curve(os.path.join(root_path, 'to', 'curve', 'two'))
>>> c.info['note'] = 'The second curve'
>>> p.append_curve(c)
>>> p.digest()
'f\xe26i\xb98i\x1f\xb61J7:\xf2\x8e\x1d\xde\xc3}g'
Create a string representation of the playlist.
A playlist is a YAML document with the following minimal syntax:
!!python/object/new:hooke.playlist.FilePlaylist
state:
version: '0.2'
listitems:
- !!python/object:hooke.curve.Curve
path: /path/to/curve/one
- !!python/object:hooke.curve.Curve
path: /path/to/curve/two
Relative paths are interpreted relative to the location of the playlist file.
Examples
>>> from .engine import CommandMessage
>>> root_path = os.path.sep + 'path'
>>> p = FilePlaylist(drivers=[],
... path=os.path.join(root_path, 'to','playlist'))
>>> p.info['note'] = 'An example playlist'
>>> c = Curve(os.path.join(root_path, 'to', 'curve', 'one'))
>>> c.info['note'] = 'The first curve'
>>> p.append_curve(c)
>>> c = Curve(os.path.join(root_path, 'to', 'curve', 'two'))
>>> c.info['attr with spaces'] = 'The second curve\nwith endlines'
>>> c.command_stack.extend([
... CommandMessage('command A', {'arg 0':0, 'arg 1':'X'}),
... CommandMessage('command B', {'arg 0':1, 'curve':c}),
... ])
>>> p.append_curve(c)
>>> print p.flatten()
# Hooke playlist version 0.2
!!python/object/new:hooke.playlist.FilePlaylist
listitems:
- !!python/object:hooke.curve.Curve
info: {note: The first curve}
name: one
path: curve/one
- &id001 !!python/object:hooke.curve.Curve
command_stack: !!python/object/new:hooke.command_stack.CommandStack
listitems:
- !!python/object:hooke.engine.CommandMessage
arguments: {arg 0: 0, arg 1: X}
command: command A
explicit_user_call: true
- !!python/object:hooke.engine.CommandMessage
arguments:
arg 0: 1
curve: *id001
command: command B
explicit_user_call: true
info: {attr with spaces: 'The second curve
<BLANKLINE>
with endlines'}
name: two
path: curve/two
state:
_base_path: /path/to
info: {note: An example playlist}
name: playlist.hkp
path: /path/to/playlist.hkp
version: '0.2'
<BLANKLINE>
>>> p.relative_curve_paths = False
>>> print p.flatten()
# Hooke playlist version 0.2
!!python/object/new:hooke.playlist.FilePlaylist
listitems:
- !!python/object:hooke.curve.Curve
info: {note: The first curve}
name: one
path: /path/to/curve/one
- &id001 !!python/object:hooke.curve.Curve
command_stack: !!python/object/new:hooke.command_stack.CommandStack
listitems:
- !!python/object:hooke.engine.CommandMessage
arguments: {arg 0: 0, arg 1: X}
command: command A
explicit_user_call: true
- !!python/object:hooke.engine.CommandMessage
arguments:
arg 0: 1
curve: *id001
command: command B
explicit_user_call: true
info: {attr with spaces: 'The second curve
<BLANKLINE>
with endlines'}
name: two
path: /path/to/curve/two
state:
_base_path: /path/to
info: {note: An example playlist}
name: playlist.hkp
path: /path/to/playlist.hkp
relative_curve_paths: false
version: '0.2'
<BLANKLINE>
Saves the playlist to a YAML file.
A list that keeps track of a “current” item and additional notes.
index (i.e. “bookmark”) is the index of the currently current curve. Also keep a dict of additional information (info).
Methods
append | |
count | |
current | |
extend | |
filter | |
index | |
insert | |
items | |
jump | |
next | |
pop | |
previous | |
remove | |
reverse | |
sort |
Extend list.index, returning the current index if value is None.
Iterate through self calling _setup_item on each item before yielding.
Notes
Updates _index during the iteration so current_curve_callback() works as expected in Commands called from ApplyCommand. After the iteration completes, _index is restored to its original value.
A NoteIndexList of hooke.Curves.
Keeps a list of drivers for loading curves.
Methods
append | |
append_curve | |
append_curve_by_path | |
count | |
current | |
extend | |
filter | |
index | |
insert | |
items | |
jump | |
next | |
pop | |
previous | |
remove | |
reverse | |
sort | |
unload |
Inverse of ._setup_item.
A NoteIndexList of FilePlaylists.
Methods
append | |
count | |
current | |
extend | |
filter | |
index | |
insert | |
items | |
jump | |
next | |
pop | |
previous | |
remove | |
reverse | |
sort |
Load a playlist from a string.
Examples
Minimal example.
>>> string = '''# Hooke playlist version 0.2
... !!python/object/new:hooke.playlist.FilePlaylist
... state:
... version: '0.2'
... listitems:
... - !!python/object:hooke.curve.Curve
... path: curve/one
... - !!python/object:hooke.curve.Curve
... path: curve/two
... '''
>>> p = from_string(string)
>>> p.set_path('/path/to/playlist')
>>> for curve in p:
... print curve.name, curve.path
one /path/to/curve/one
two /path/to/curve/two
More complicated example.
>>> string = '''# Hooke playlist version 0.2
... !!python/object/new:hooke.playlist.FilePlaylist
... listitems:
... - !!python/object:hooke.curve.Curve
... info: {note: The first curve}
... name: one
... path: /path/to/curve/one
... - &id001 !!python/object:hooke.curve.Curve
... command_stack: !!python/object/new:hooke.command_stack.CommandStack
... listitems:
... - !!python/object:hooke.engine.CommandMessage
... arguments: {arg 0: 0, arg 1: X}
... command: command A
... - !!python/object:hooke.engine.CommandMessage
... arguments:
... arg 0: 1
... curve: *id001
... command: command B
... info: {attr with spaces: 'The second curve
...
... with endlines'}
... name: two
... path: /path/to/curve/two
... state:
... _base_path: /path/to
... _index: 1
... info: {note: An example playlist}
... name: playlist.hkp
... path: /path/to/playlist.hkp
... version: '0.2'
... '''
>>> p = from_string(string)
>>> p.set_path('/path/to/playlist')
>>> p._index
1
>>> p.info
{'note': 'An example playlist'}
>>> for curve in p:
... print curve.name, curve.path
one /path/to/curve/one
two /path/to/curve/two
>>> p[-1].info['attr with spaces']
'The second curve\nwith endlines'
>>> type(p[-1].command_stack)
<class 'hooke.command_stack.CommandStack'>
>>> p[0].command_stack
[]
>>> type(p[0].command_stack)
<class 'hooke.command_stack.CommandStack'>
>>> p[-1].command_stack
[<CommandMessage command A {arg 0: 0, arg 1: X}>,
<CommandMessage command B {arg 0: 1, curve: <Curve two>}>]
>>> type(p[1].command_stack)
<class 'hooke.command_stack.CommandStack'>
>>> c2 = p[-1]
>>> c2.command_stack[-1].arguments['curve'] == c2
True
Load a playlist from a file.
Normalize playlist path extensions.
Examples
>>> print playlist_path('playlist')
playlist.hkp
>>> print playlist_path('playlist.hkp')
playlist.hkp
>>> print playlist_path(None)
None