summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/core
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2018-12-27 22:09:55 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2018-12-27 22:09:55 (GMT)
commitc8dce9ce407b2f8248d669df196a4bf0f9523723 (patch)
treef7ea7baa0c83fb2de1ae8e402b342e345493cdc3 /plugins/pychrysalide/core
parent4b1367d2fee7be0789744e1db35d6f9200b29163 (diff)
Updated the logging features of the Python bindings.
Diffstat (limited to 'plugins/pychrysalide/core')
-rw-r--r--plugins/pychrysalide/core/logs.c139
-rw-r--r--plugins/pychrysalide/core/logs.h7
-rw-r--r--plugins/pychrysalide/core/module.c2
3 files changed, 48 insertions, 100 deletions
diff --git a/plugins/pychrysalide/core/logs.c b/plugins/pychrysalide/core/logs.c
index 38084c4..f2158f9 100644
--- a/plugins/pychrysalide/core/logs.c
+++ b/plugins/pychrysalide/core/logs.c
@@ -33,6 +33,7 @@
#include "../access.h"
#include "../helpers.h"
+#include "../pychrysa.h"
@@ -46,13 +47,13 @@ static PyObject *py_logs_set_verbosity(PyObject *, PyObject *);
static PyObject *py_logs_log_message(PyObject *, PyObject *);
/* Définit les constantes pour les types de message. */
-static bool define_python_log_constants(PyTypeObject *);
+static bool define_python_log_constants(PyObject *);
/******************************************************************************
* *
-* Paramètres : self = classe assurant le lien avec l'éditeur de messages. *
+* Paramètres : self = objet Python concerné par l'appel. *
* args = arguments fournis à l'appel. *
* *
* Description : Fournit la verbosité des messages système. *
@@ -79,7 +80,7 @@ static PyObject *py_logs_get_verbosity(PyObject *self, PyObject *args)
/******************************************************************************
* *
-* Paramètres : self = classe assurant le lien avec l'éditeur de messages. *
+* Paramètres : self = objet Python concerné par l'appel. *
* args = arguments fournis à l'appel. *
* *
* Description : Définit la verbosité des messages système. *
@@ -110,7 +111,7 @@ static PyObject *py_logs_set_verbosity(PyObject *self, PyObject *args)
/******************************************************************************
* *
-* Paramètres : self = classe assurant le lien avec l'éditeur de messages. *
+* Paramètres : self = objet Python concerné par l'appel. *
* args = arguments fournis à l'appel. *
* *
* Description : Affiche un message dans le journal des messages système. *
@@ -138,7 +139,7 @@ static PyObject *py_logs_log_message(PyObject *self, PyObject *args)
case LMT_BAD_BINARY:
case LMT_ERROR:
case LMT_EXT_ERROR:
- log_simple_message(type, msg);
+ log_pychrysalide_simple_message(type, msg);
result = Py_None;
Py_INCREF(result);
break;
@@ -158,66 +159,7 @@ static PyObject *py_logs_log_message(PyObject *self, PyObject *args)
/******************************************************************************
* *
-* Paramètres : - *
-* *
-* Description : Fournit un accès à une définition de type à diffuser. *
-* *
-* Retour : Définition d'objet pour Python. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-PyTypeObject *get_python_logs_type(void)
-{
- static PyMethodDef py_logs_methods[] = {
- {
- "get_verbosity", py_logs_get_verbosity,
- METH_NOARGS | METH_STATIC,
- "get_verbosity(, /)\n--\n\nGet the log verbosity."
- },
- {
- "set_verbosity", py_logs_set_verbosity,
- METH_VARARGS | METH_STATIC,
- "set_verbosity(, /)\n--\n\nSet the log verbosity."
- },
- {
- "log_message", py_logs_log_message,
- METH_VARARGS | METH_STATIC,
- "log_message(type, msg, /)\n--\n\nDisplay a message in the log window, if any."
- },
- { NULL }
-
- };
-
- static PyGetSetDef py_logs_getseters[] = {
- { NULL }
- };
-
- static PyTypeObject py_logs_type = {
-
- PyVarObject_HEAD_INIT(NULL, 0)
-
- .tp_name = "pychrysalide.core.logs",
- .tp_basicsize = sizeof(PyObject) + 80,
-
- .tp_flags = Py_TPFLAGS_DEFAULT,
-
- .tp_doc = "Access to the core log facilities",
-
- .tp_methods = py_logs_methods,
- .tp_getset = py_logs_getseters
-
- };
-
- return &py_logs_type;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : obj_type = type dont le dictionnaire est à compléter. *
+* Paramètres : dict = dictionnaire de module à compléter. *
* *
* Description : Définit les constantes pour les types de message. *
* *
@@ -227,19 +169,19 @@ PyTypeObject *get_python_logs_type(void)
* *
******************************************************************************/
-static bool define_python_log_constants(PyTypeObject *obj_type)
+static bool define_python_log_constants(PyObject *dict)
{
bool result; /* Bilan à retourner */
result = true;
- result &= PyDict_AddULongMacro(obj_type, LMT_INFO);
- result &= PyDict_AddULongMacro(obj_type, LMT_PROCESS);
- result &= PyDict_AddULongMacro(obj_type, LMT_WARNING);
- result &= PyDict_AddULongMacro(obj_type, LMT_BAD_BINARY);
- result &= PyDict_AddULongMacro(obj_type, LMT_ERROR);
- result &= PyDict_AddULongMacro(obj_type, LMT_EXT_ERROR);
- result &= PyDict_AddULongMacro(obj_type, LMT_COUNT);
+ result &= PyModDict_AddULongMacro(dict, LMT_INFO);
+ result &= PyModDict_AddULongMacro(dict, LMT_PROCESS);
+ result &= PyModDict_AddULongMacro(dict, LMT_WARNING);
+ result &= PyModDict_AddULongMacro(dict, LMT_BAD_BINARY);
+ result &= PyModDict_AddULongMacro(dict, LMT_ERROR);
+ result &= PyModDict_AddULongMacro(dict, LMT_EXT_ERROR);
+ result &= PyModDict_AddULongMacro(dict, LMT_COUNT);
return result;
@@ -248,9 +190,9 @@ static bool define_python_log_constants(PyTypeObject *obj_type)
/******************************************************************************
* *
-* Paramètres : module = module dont la définition est à compléter. *
+* Paramètres : - *
* *
-* Description : Prend en charge l'objet 'pychrysalide.gui.panels.LogPanel'. *
+* Description : Définit une extension du module 'core' à compléter. *
* *
* Retour : Bilan de l'opération. *
* *
@@ -258,34 +200,43 @@ static bool define_python_log_constants(PyTypeObject *obj_type)
* *
******************************************************************************/
-bool ensure_python_logs_is_registered(void)
+bool populate_core_module_with_logs(void)
{
- PyTypeObject *type; /* Type Python pour 'logs' */
+ bool result; /* Bilan à retourner */
PyObject *module; /* Module à recompléter */
- int ret; /* Bilan d'un appel */
+ PyObject *dict; /* Dictionnaire dudit module */
- type = get_python_logs_type();
+ static PyMethodDef py_queue_methods[] = {
- if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
- {
- type->tp_new = PyType_GenericNew;
-
- if (PyType_Ready(type) != 0)
- return false;
-
- if (!define_python_log_constants(type))
- return false;
+ {
+ "get_verbosity", py_logs_get_verbosity,
+ METH_NOARGS,
+ "get_verbosity(, /)\n--\n\nGet the log verbosity."
+ },
+ {
+ "set_verbosity", py_logs_set_verbosity,
+ METH_VARARGS,
+ "set_verbosity(, /)\n--\n\nSet the log verbosity."
+ },
+ {
+ "log_message", py_logs_log_message,
+ METH_VARARGS,
+ "log_message(type, msg, /)\n--\n\nDisplay a message in the log window, if any."
+ },
+ { NULL }
- module = get_access_to_python_module("pychrysalide.core");
+ };
- Py_INCREF(type);
- ret = PyModule_AddObject(module, "logs", (PyObject *)type);
+ module = get_access_to_python_module("pychrysalide.core");
- if (ret != 0)
- return false;
+ result = register_python_module_methods(module, py_queue_methods);
+ if (result)
+ {
+ dict = PyModule_GetDict(module);
+ result = define_python_log_constants(dict);
}
- return true;
+ return result;
}
diff --git a/plugins/pychrysalide/core/logs.h b/plugins/pychrysalide/core/logs.h
index 3165897..ed27808 100644
--- a/plugins/pychrysalide/core/logs.h
+++ b/plugins/pychrysalide/core/logs.h
@@ -31,11 +31,8 @@
-/* Fournit un accès à une définition de type à diffuser. */
-PyTypeObject *get_python_logs_type(void);
-
-/* Prend en charge l'objet 'pychrysalide.core.logs'. */
-bool ensure_python_logs_is_registered(void);
+/* Définit une extension du module 'core' à compléter. */
+bool populate_core_module_with_logs(void);
diff --git a/plugins/pychrysalide/core/module.c b/plugins/pychrysalide/core/module.c
index 900bf83..c786ad6 100644
--- a/plugins/pychrysalide/core/module.c
+++ b/plugins/pychrysalide/core/module.c
@@ -94,7 +94,7 @@ bool populate_core_module(void)
if (result) result = ensure_python_demanglers_is_registered();
if (result) result = populate_core_module_with_global();
- if (result) result = ensure_python_logs_is_registered();
+ if (result) result = populate_core_module_with_logs();
if (result) result = ensure_python_params_is_registered();
if (result) result = populate_core_module_with_queue();