bindings: python: provide gpiod.version_string()
authorBartosz Golaszewski <bartekgola@gmail.com>
Wed, 16 May 2018 08:36:28 +0000 (10:36 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Wed, 16 May 2018 08:39:11 +0000 (10:39 +0200)
Implement a python wrapper around gpiod_version_string().

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
bindings/python/examples/gpiod_tests.py
bindings/python/gpiodmodule.c

index e6cc23027bc8b2f0b8d7a30b7dc278def21ffbd8..dfc3f14d88f53279f2bf75ba23a95fad63a94744 100755 (executable)
@@ -298,6 +298,8 @@ def line_event_poll_fd():
 
 add_test('Monitor multiple lines using their file descriptors', line_event_poll_fd)
 
+print('API version is {}'.format(gpiod.version_string()))
+
 for name, func in test_cases:
     print('==============================================')
     print('{}:'.format(name))
index 8f8ac28f6285dd07b8fc19d4de18310d6e5c54cd..2a5db5f61db98d81e5090cd4c26494cab66bf5f8 100644 (file)
@@ -1783,6 +1783,14 @@ static gpiod_LineObject *gpiod_Module_find_line(PyObject *self GPIOD_UNUSED,
        return line_obj;
 }
 
+PyDoc_STRVAR(gpiod_Module_version_string_doc,
+"Get the API version of the library as a human-readable string.");
+
+static PyObject *gpiod_Module_version_string(void)
+{
+       return PyUnicode_FromFormat("%s", gpiod_version_string());
+}
+
 static PyMethodDef gpiod_module_methods[] = {
        {
                .ml_name = "find_line",
@@ -1790,6 +1798,12 @@ static PyMethodDef gpiod_module_methods[] = {
                .ml_flags = METH_VARARGS,
                .ml_doc = gpiod_Module_find_line_doc,
        },
+       {
+               .ml_name = "version_string",
+               .ml_meth = (PyCFunction)gpiod_Module_version_string,
+               .ml_flags = METH_NOARGS,
+               .ml_doc = gpiod_Module_version_string_doc,
+       },
        { }
 };