constant: Use dir(comedi.wrapped) when comedi.wrapped exists
authorW. Trevor King <wking@tremily.us>
Thu, 17 Jul 2014 17:35:00 +0000 (10:35 -0700)
committerW. Trevor King <wking@tremily.us>
Thu, 17 Jul 2014 17:52:05 +0000 (10:52 -0700)
Since 371dcc5 (swig: remove comedi_ prefix from the function names,
2014-01-31, released in comedilib 0.10.2), dir(comedi) no longer lists
the meaty-bits:

  >>> import comedi
  >>> comedi.CR_ALT_FILTER
  67108864
  >>> [attr for attr in dir(comedi) if attr.startswith('CR_')]

Instead, they have shifted to comedi.wrapped:

  >>> [attr for attr in dir(comedi.wrapped) if attr.startswith('CR_')]
  ['CR_ALT_FILTER', 'CR_ALT_SOURCE', 'CR_DEGLITCH', 'CR_DITHER', 'CR_EDGE',
   'CR_FLAGS_MASK', 'CR_INVERT']

This commit adjusts pycomedi to use comedi.wrapped when it exists, so
pycomedi will work with the new comedilib (and continue working with
the old comedilibs).

I also have to remove 'COMEDI_' from the prefixes that contain it to
catch up with 371dcc5:

  +%rename("%(strip:[COMEDI_])s", regextarget=1) "COMEDI_.*";

Reported-by: Colin Jermain <clj72@cornell.edu>
pycomedi/constant.pyx

index 196650aef5e36434d53d278e1888af4500bbf282..41c669ceedbbccbb5a2d55570680f71e95ac3146 100644 (file)
@@ -231,7 +231,12 @@ class _Enum (list):
             translation = {}
         self._name_keys = {}
         self._value_keys = {}
-        for attr in dir(_comedi):
+        mod = _comedi
+        if hasattr(mod, 'wrapped'):
+            mod = mod.wrapped
+            if prefix.startswith('COMEDI_'):
+                prefix = prefix[len('COMEDI_'):]
+        for attr in dir(mod):
             if attr.startswith(prefix):
                 item_name = self._item_name(attr, prefix, translation)
                 if self._is_ignored(item_name, blacklist, whitelist):