diff options
Diffstat (limited to 'src/modules/python')
| -rw-r--r-- | src/modules/python/libkvipython.cpp | 107 |
1 files changed, 53 insertions, 54 deletions
diff --git a/src/modules/python/libkvipython.cpp b/src/modules/python/libkvipython.cpp index a77646b38..4a44370b8 100644 --- a/src/modules/python/libkvipython.cpp +++ b/src/modules/python/libkvipython.cpp @@ -28,35 +28,35 @@ #include "KviLocale.h" #ifdef COMPILE_PYTHON_SUPPORT - #include "../pythoncore/pythoncoreinterface.h" - #include <Python.h> +#include "../pythoncore/pythoncoreinterface.h" +#include <Python.h> - static KviModule * g_pPythonCoreModule = nullptr; +static KviModule * g_pPythonCoreModule = nullptr; - #define KVS_CHECK_PYTHONCORE(_m,_c) \ - g_pPythonCoreModule = g_pModuleManager->getModule("pythoncore"); \ - if(!g_pPythonCoreModule) \ - { \ - if(!_c->switches()->find('q',"quiet")) \ - { \ - _c->warning(__tr2qs_ctx("The pythoncore module can't be loaded: Python support not available","python")); \ - _c->warning(__tr2qs_ctx("To see more details about loading failure try /pythoncore.load","python")); \ - return true; \ - } \ - } +#define KVS_CHECK_PYTHONCORE(_m, _c) \ + g_pPythonCoreModule = g_pModuleManager->getModule("pythoncore"); \ + if(!g_pPythonCoreModule) \ + { \ + if(!_c->switches()->find('q', "quiet")) \ + { \ + _c->warning(__tr2qs_ctx("The pythoncore module can't be loaded: Python support not available", "python")); \ + _c->warning(__tr2qs_ctx("To see more details about loading failure try /pythoncore.load", "python")); \ + return true; \ + } \ + } - #define KVS_CHECK_MODULE_STATE(_m,_c) KVS_CHECK_PYTHONCORE(_m,_c) +#define KVS_CHECK_MODULE_STATE(_m, _c) KVS_CHECK_PYTHONCORE(_m, _c) #else // COMPILE_PYTHON_SUPPORT - #define KVS_CHECK_PYTHONCORE(_m,_c) +#define KVS_CHECK_PYTHONCORE(_m, _c) - #define KVS_CHECK_MODULE_STATE(_m,_c) \ - if(!_c->switches()->find('q',"quiet")) \ - _c->warning(__tr2qs_ctx("This KVIrc executable has been compiled without Python scripting support","python")); \ - return true; +#define KVS_CHECK_MODULE_STATE(_m, _c) \ + if(!_c->switches()->find('q', "quiet")) \ + _c->warning(__tr2qs_ctx("This KVIrc executable has been compiled without Python scripting support", "python")); \ + return true; - static KviModule * g_pPythonCoreModule = nullptr; +static KviModule * g_pPythonCoreModule = nullptr; #endif // COMPILE_PYTHON_SUPPORT /* @@ -387,15 +387,15 @@ static bool python_kvs_cmd_begin(KviKvsModuleCommandCall * c) // The parser sets the Python code as the first parameter of our call, // the remaining params are the context name and the arguments - QString szCode,szContext; + QString szCode, szContext; KviKvsVariantList vList; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("code",KVS_PT_STRING,0,szCode) - KVSM_PARAMETER("context",KVS_PT_STRING,KVS_PF_OPTIONAL,szContext) - KVSM_PARAMETER("args",KVS_PT_VARIANTLIST,KVS_PF_OPTIONAL,vList) + KVSM_PARAMETER("code", KVS_PT_STRING, 0, szCode) + KVSM_PARAMETER("context", KVS_PT_STRING, KVS_PF_OPTIONAL, szContext) + KVSM_PARAMETER("args", KVS_PT_VARIANTLIST, KVS_PF_OPTIONAL, vList) KVSM_PARAMETERS_END(c) - KVS_CHECK_MODULE_STATE(m,c) + KVS_CHECK_MODULE_STATE(m, c) #ifdef COMPILE_PYTHON_SUPPORT KviPythonCoreCtrlCommand_execute ex; @@ -403,37 +403,37 @@ static bool python_kvs_cmd_begin(KviKvsModuleCommandCall * c) ex.pKvsContext = c->context(); ex.szContext = szContext; ex.szCode = szCode; - for(KviKvsVariant * v = vList.first();v;v = vList.next()) + for(KviKvsVariant * v = vList.first(); v; v = vList.next()) { QString tmp; v->asString(tmp); ex.lArgs.append(tmp); } - ex.bQuiet = c->switches()->find('q',"quiet"); + ex.bQuiet = c->switches()->find('q', "quiet"); - if(!g_pPythonCoreModule->ctrl(KVI_PYTHONCORECTRLCOMMAND_EXECUTE,&ex)) + if(!g_pPythonCoreModule->ctrl(KVI_PYTHONCORECTRLCOMMAND_EXECUTE, &ex)) { - if(!c->switches()->find('q',"quiet")) - c->warning(__tr2qs_ctx("The pythoncore module failed to execute the code: something is wrong with the Python support","python")); + if(!c->switches()->find('q', "quiet")) + c->warning(__tr2qs_ctx("The pythoncore module failed to execute the code: something is wrong with the Python support", "python")); return true; } if(!ex.lWarnings.isEmpty()) { - for(const auto& it : ex.lWarnings) + for(const auto & it : ex.lWarnings) c->warning(it); } - if(!ex.bExitOk && !c->switches()->find('q',"quiet")) + if(!ex.bExitOk && !c->switches()->find('q', "quiet")) { - c->warning(__tr2qs_ctx("Python execution error:","python")); + c->warning(__tr2qs_ctx("Python execution error:", "python")); c->warning(ex.szError); - if(c->switches()->find('f',"fail-on-error")) + if(c->switches()->find('f', "fail-on-error")) return false; } - if(!c->switches()->find('n',"no-return")) + if(!c->switches()->find('n', "no-return")) c->context()->returnValue()->setString(ex.szRetVal); #endif //COMPILE_PYTHON_SUPPORT @@ -467,20 +467,20 @@ static bool python_kvs_cmd_destroy(KviKvsModuleCommandCall * c) { QString szContext; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("context",KVS_PT_NONEMPTYSTRING,0,szContext) + KVSM_PARAMETER("context", KVS_PT_NONEMPTYSTRING, 0, szContext) KVSM_PARAMETERS_END(c) - KVS_CHECK_MODULE_STATE(m,c) + KVS_CHECK_MODULE_STATE(m, c) #ifdef COMPILE_PYTHON_SUPPORT KviPythonCoreCtrlCommand_destroy ex; ex.uSize = sizeof(KviPythonCoreCtrlCommand_destroy); ex.szContext = szContext; - if(!g_pPythonCoreModule->ctrl(KVI_PYTHONCORECTRLCOMMAND_DESTROY,&ex)) + if(!g_pPythonCoreModule->ctrl(KVI_PYTHONCORECTRLCOMMAND_DESTROY, &ex)) { - if(!c->switches()->find('q',"quiet")) - c->warning(__tr2qs_ctx("The pythoncore module failed to execute the code: something is wrong with the Python support","python")); + if(!c->switches()->find('q', "quiet")) + c->warning(__tr2qs_ctx("The pythoncore module failed to execute the code: something is wrong with the Python support", "python")); } #endif //COMPILE_PYTHON_SUPPORT @@ -515,10 +515,10 @@ static bool python_kvs_fnc_isAvailable(KviKvsModuleFunctionCall * c) static bool python_module_init(KviModule * m) { // register the command anyway - KVSM_REGISTER_SIMPLE_COMMAND(m,"begin",python_kvs_cmd_begin); - KVSM_REGISTER_SIMPLE_COMMAND(m,"destroy",python_kvs_cmd_destroy); + KVSM_REGISTER_SIMPLE_COMMAND(m, "begin", python_kvs_cmd_begin); + KVSM_REGISTER_SIMPLE_COMMAND(m, "destroy", python_kvs_cmd_destroy); - KVSM_REGISTER_FUNCTION(m,"isAvailable",python_kvs_fnc_isAvailable); + KVSM_REGISTER_FUNCTION(m, "isAvailable", python_kvs_fnc_isAvailable); #ifdef COMPILE_PYTHON_SUPPORT g_pPythonCoreModule = g_pModuleManager->getModule("pythoncore"); #endif @@ -531,13 +531,12 @@ static bool python_module_cleanup(KviModule *) } KVIRC_MODULE( - "Python", // module name - "4.0.0", // module version - "Copyright (C) 2008 Elvio Basello (hellvis69 at netsons dot org", // author & (C) - "Python Scripting Engine", - python_module_init, - 0, - 0, - python_module_cleanup, - "python" -) + "Python", // module name + "4.0.0", // module version + "Copyright (C) 2008 Elvio Basello (hellvis69 at netsons dot org", // author & (C) + "Python Scripting Engine", + python_module_init, + 0, + 0, + python_module_cleanup, + "python") |
