Tracked down problems saving playlists with loaded curves to numpy.dtype
authorW. Trevor King <wking@drexel.edu>
Sat, 21 Aug 2010 17:44:05 +0000 (13:44 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 21 Aug 2010 17:44:05 +0000 (13:44 -0400)
hooke/playlist.py

index 9ee31259f780e633eb0a25afc0148bd46a244901..b996a5f7777c460de74268c528e1897c4e7a7eb2 100644 (file)
@@ -27,6 +27,24 @@ import os
 import os.path
 import types
 
+if False: # YAML dump debugging code
+    """To help isolate data types etc. that give YAML problems.
+
+    This is usually caused by external C modules (e.g. numpy) that
+    define new types (e.g. numpy.dtype) which YAML cannot inspect.
+    """
+    import yaml.representer
+    import sys
+    def ignore_aliases(data):
+        print data, type(data)
+        sys.stdout.flush()
+        if data in [None, ()]:
+            return True
+        if isinstance(data, (str, unicode, bool, int, float)):
+            return True
+    yaml.representer.SafeRepresenter.ignore_aliases = staticmethod(
+        ignore_aliases)
+
 import yaml
 from yaml.representer import RepresenterError
 
@@ -103,10 +121,10 @@ class NoteIndexList (list):
                 continue
             try:
                 yaml.dump((k,v))
-            except (TypeError, RepresenterError), e:
+            except RepresenterError, e:
                 raise NotImplementedError(
-                    'cannot convert %s.%s = %s (%s) to YAML'
-                    % (owner.__class__.__name__, k, v, type(v)))
+                    'cannot convert %s.%s = %s (%s) to YAML\n%s'
+                    % (owner.__class__.__name__, k, v, type(v), e))
 
     def _setup_item(self, item):
         """Perform any required initialization before returning an item.
@@ -197,10 +215,9 @@ class Playlist (NoteIndexList):
         self._ignored_attrs.extend([
                 '_item_ignored_attrs', '_item_default_attrs',
                 '_loaded'])
-        self._item_ignored_attrs = []
+        self._item_ignored_attrs = ['data']
         self._item_default_attrs = {
             'command_stack': [],
-            'data': None,
             'driver': None,
             'info': {},
             'name': None,