| 1551 | } |
| 1552 | |
| 1553 | std::vector<CapabilityInfo> list_capabilities() { |
| 1554 | std::vector<CapabilityInfo> result; |
| 1555 | ensure_initialized(); |
| 1556 | ensure_plugins_loaded(); |
| 1557 | const GilAcquire gil; |
| 1558 | |
| 1559 | PyObject* lfs_plugins = PyImport_ImportModule("lfs_plugins"); |
| 1560 | if (lfs_plugins) { |
| 1561 | PyObject* registry_class = PyObject_GetAttrString(lfs_plugins, "CapabilityRegistry"); |
| 1562 | if (registry_class) { |
| 1563 | PyObject* instance_method = PyObject_GetAttrString(registry_class, "instance"); |
| 1564 | PyObject* registry = PyObject_CallNoArgs(instance_method); |
| 1565 | if (registry) { |
| 1566 | PyObject* list_method = PyObject_GetAttrString(registry, "list_all"); |
| 1567 | PyObject* caps = PyObject_CallNoArgs(list_method); |
| 1568 | if (caps && PyList_Check(caps)) { |
| 1569 | const Py_ssize_t n = PyList_Size(caps); |
| 1570 | for (Py_ssize_t i = 0; i < n; ++i) { |
| 1571 | PyObject* cap = PyList_GetItem(caps, i); |
| 1572 | CapabilityInfo info; |
| 1573 | |
| 1574 | PyObject* name = PyObject_GetAttrString(cap, "name"); |
| 1575 | if (name && PyUnicode_Check(name)) |
| 1576 | info.name = PyUnicode_AsUTF8(name); |
| 1577 | Py_XDECREF(name); |
| 1578 | |
| 1579 | PyObject* desc = PyObject_GetAttrString(cap, "description"); |
| 1580 | if (desc && PyUnicode_Check(desc)) |
| 1581 | info.description = PyUnicode_AsUTF8(desc); |
| 1582 | Py_XDECREF(desc); |
| 1583 | |
| 1584 | PyObject* plugin = PyObject_GetAttrString(cap, "plugin_name"); |
| 1585 | if (plugin && PyUnicode_Check(plugin)) |
| 1586 | info.plugin_name = PyUnicode_AsUTF8(plugin); |
| 1587 | Py_XDECREF(plugin); |
| 1588 | |
| 1589 | result.push_back(info); |
| 1590 | } |
| 1591 | Py_DECREF(caps); |
| 1592 | } |
| 1593 | Py_DECREF(list_method); |
| 1594 | Py_DECREF(registry); |
| 1595 | } |
| 1596 | Py_DECREF(instance_method); |
| 1597 | Py_DECREF(registry_class); |
| 1598 | } |
| 1599 | Py_DECREF(lfs_plugins); |
| 1600 | } |
| 1601 | |
| 1602 | return result; |
| 1603 | } |
| 1604 | |
| 1605 | } // namespace lfs::python |
no test coverage detected