Fix modpython to show list of available modules

In 1.8.0 I switched from deprecated imp to importlib for loading module
by name, but forgot about this function

Close #1884
This commit is contained in:
Alexey Sokolov
2023-10-26 00:29:03 +01:00
parent bf5805d9a9
commit aa5016657b
3 changed files with 12 additions and 61 deletions

View File

@@ -289,42 +289,17 @@ class CModPython : public CModule {
return HALT;
}
void TryAddModInfo(const CString& sPath, const CString& sName,
void TryAddModInfo(const CString& sName,
set<CModInfo>& ssMods, set<CString>& ssAlready,
CModInfo::EModuleType eType) {
if (ssAlready.count(sName)) {
return;
}
PyObject* pyFunc =
PyObject_GetAttrString(m_PyZNCModule, "get_mod_info_path");
if (!pyFunc) {
CString sRetMsg = GetPyExceptionStr();
DEBUG("modpython tried to get info about ["
<< sPath << "] (1) but: " << sRetMsg);
return;
}
CModInfo ModInfo;
PyObject* pyRes = PyObject_CallFunction(
pyFunc, const_cast<char*>("ssN"), sPath.c_str(), sName.c_str(),
SWIG_NewInstanceObj(&ModInfo, SWIG_TypeQuery("CModInfo*"), 0));
if (!pyRes) {
CString sRetMsg = GetPyExceptionStr();
DEBUG("modpython tried to get info about ["
<< sPath << "] (2) but: " << sRetMsg);
Py_CLEAR(pyFunc);
return;
}
Py_CLEAR(pyFunc);
long int x = PyLong_AsLong(pyRes);
if (PyErr_Occurred()) {
CString sRetMsg = GetPyExceptionStr();
DEBUG("modpython tried to get info about ["
<< sPath << "] (3) but: " << sRetMsg);
Py_CLEAR(pyRes);
return;
}
Py_CLEAR(pyRes);
if (x && ModInfo.SupportsType(eType)) {
bool bSuccess = false;
CString sRetMsg;
OnGetModInfo(ModInfo, sName, bSuccess, sRetMsg);
if (bSuccess && ModInfo.SupportsType(eType)) {
ssMods.insert(ModInfo);
ssAlready.insert(sName);
}
@@ -342,20 +317,18 @@ class CModPython : public CModule {
for (unsigned int a = 0; a < Dir.size(); a++) {
CFile& File = *Dir[a];
CString sName = File.GetShortName();
CString sPath = File.GetLongName();
sPath.TrimSuffix(sName);
if (!File.IsDir()) {
if (sName.WildCmp("*.pyc")) {
sName.RightChomp(4);
} else if (sName.WildCmp("*.py") || sName.WildCmp("*.so")) {
} else if (sName.WildCmp("*.py")) {
sName.RightChomp(3);
} else {
continue;
}
}
TryAddModInfo(sPath, sName, ssMods, already, eType);
TryAddModInfo(sName, ssMods, already, eType);
}
dirs.pop();