From b680a1c785821a5a37a87973b9f66bfaf4b4b1ba Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 19 Oct 2012 09:19:15 -0400 Subject: [PATCH] info.py: add optional kmod modinfo section. The older info.py version only used comedilib to extract board information, including the comedi version in use. While the out-of-kernel comedi module does bump their versions (occasionally ;), the in-kernel staging drivers still claim version 0.7.76 (despite being mostly equivalent to the out-of-tree module 0.10.1). This makes it useful to differentiate between in-kernel and out-of-kernel modules by printing some modinfo details, for which I'm using the kmod Python bindings (python-kmod). I'm currently using my Cython branch of python-kmod, which is pending a merge upstream [1]. [1]: https://github.com/agrover/python-kmod/pull/3 --- doc/demo/info.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/doc/demo/info.py b/doc/demo/info.py index e5c76e4..ce3f176 100755 --- a/doc/demo/info.py +++ b/doc/demo/info.py @@ -19,12 +19,39 @@ """Gather and display information about a comedi device. """ +try: + import kmod as _kmod + import kmod.error as _kmod_error +except ImportError as e: + _kmod = None + _kmod_import_error = e + from pycomedi import PyComediError as _PyComediError import pycomedi.constant as _constant from pycomedi.device import Device as _Device from pycomedi.subdevice import StreamingSubdevice as _StreamingSubdevice +class ModuleNotFound (ValueError): + pass + + +def display_modinfo(module_name): + if _kmod is None: + raise _kmod_import_error + kmod = _kmod.Kmod() + mod = kmod.module_from_name(name=module_name) + items = [('filename', mod.path)] + try: + items.extend(mod.info.items()) + except _kmod_error.KmodError as e: + raise ModuleNotFound(module_name) + longest_key = max(len(k) for k,v in items) + print('modinfo for {}'.format(module_name)) + for k,v in items: + space = ' '*(longest_key + 4 - len(k)) + print(' {}:{}{}'.format(k, space, v)) + def display_maxdata(subdevice): if subdevice.maxdata_is_chan_specific(): print(' max data value: (channel specific)') @@ -127,6 +154,14 @@ def run(filename): ranges: command: (not supported) """ + try: + display_modinfo('comedi') + except ImportError as e: + print('could not load module info (kmod not installed)') + print(' {}'.format(e)) + except ModuleNotFound as e: + print('could not load module info (module not found)') + print(' {}'.format(e)) device = _Device(filename=filename) device.open() try: -- 2.26.2