diff --git a/modules/modpython.cpp b/modules/modpython.cpp index bf1c2ddb..52c394e4 100644 --- a/modules/modpython.cpp +++ b/modules/modpython.cpp @@ -289,42 +289,17 @@ class CModPython : public CModule { return HALT; } - void TryAddModInfo(const CString& sPath, const CString& sName, + void TryAddModInfo(const CString& sName, set& ssMods, set& 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("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(); diff --git a/modules/modpython/znc.py b/modules/modpython/znc.py index 4e8fc295..bc641cde 100644 --- a/modules/modpython/znc.py +++ b/modules/modpython/znc.py @@ -940,33 +940,6 @@ def get_mod_info(modname, retmsg, modinfo): return 2 -def get_mod_info_path(path, modname, modinfo): - try: - x = imp.find_module(modname, [path]) - except ImportError: - return 0 - # x == (, - # './modules/admin.so', ('.so', 'rb', 3)) - # x == (, - # './modules/pythontest.py', ('.py', 'U', 1)) - if x[0] is None and x[2][2] != imp.PKG_DIRECTORY: - return 0 - try: - pymodule = imp.load_module(modname, *x) - except ImportError: - return 0 - finally: - if x[0]: - x[0].close() - if modname not in pymodule.__dict__: - return 0 - cl = pymodule.__dict__[modname] - modinfo.SetName(modname) - modinfo.SetPath(pymodule.__file__) - gather_mod_info(cl, modinfo) - return 1 - - CONTINUE = CModule.CONTINUE HALT = CModule.HALT HALTMODS = CModule.HALTMODS diff --git a/test/integration/tests/scripting.cpp b/test/integration/tests/scripting.cpp index 24a45038..2ef87589 100644 --- a/test/integration/tests/scripting.cpp +++ b/test/integration/tests/scripting.cpp @@ -277,6 +277,11 @@ TEST_F(ZNCTest, ModpythonPackage) { client.Write("znc updatemod packagetest"); client.Write("PRIVMSG *packagetest :foo"); client.ReadUntil("value = b"); + // Test if python modules are viewable via *status. + // https://github.com/znc/znc/issues/1884 + client.Write("znc listavailmods"); + client.ReadUntil(":*status!status@znc.in PRIVMSG nick :\x02 packagetest"); + client.ReadUntil(":*status!status@znc.in PRIVMSG nick :\x02 pyeval\x0F: Evaluates python code"); } TEST_F(ZNCTest, ModpythonModperl) {