diff options
author | James Booth <boothj5@gmail.com> | 2016-06-22 01:09:39 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2016-06-22 01:09:39 +0100 |
commit | 620e6a5a3764c0dad6c0adb203227e7b8df84083 (patch) | |
tree | 9a0a3332a43b16c19d07707cef97649dfe3e3686 | |
parent | 3a3933eff6e59b0d29a22961802a2ef311b1d64e (diff) | |
download | profani-tty-620e6a5a3764c0dad6c0adb203227e7b8df84083.tar.gz |
Add function to get plugin name
-rw-r--r-- | src/plugins/python_api.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c index 5c4cf913..e0222e8d 100644 --- a/src/plugins/python_api.c +++ b/src/plugins/python_api.c @@ -33,6 +33,7 @@ */ #include <Python.h> +#include <frameobject.h> #include <glib.h> @@ -41,6 +42,9 @@ #include "plugins/python_plugins.h" #include "plugins/callbacks.h" #include "plugins/autocompleters.h" +#include "log.h" + +static char* _python_plugin_name(void); static PyObject* python_api_cons_alert(PyObject *self, PyObject *args) @@ -157,6 +161,9 @@ python_api_register_command(PyObject *self, PyObject *args) } c_examples[len] = NULL; + char *plugin_name = _python_plugin_name(); + log_debug("FILENAME : %s", plugin_name); + allow_python_threads(); api_register_command(command_name, min_args, max_args, c_synopsis, description, c_arguments, c_examples, p_callback, python_command_callback); @@ -790,3 +797,16 @@ python_api_init(void) { Py_InitModule("prof", apiMethods); } + +static char* +_python_plugin_name(void) +{ + PyThreadState *ts = PyThreadState_Get(); + PyFrameObject *frame = ts->frame; + char const* filename = PyString_AsString(frame->f_code->co_filename); + gchar **split = g_strsplit(filename, "/", 0); + char *plugin_name = strdup(split[g_strv_length(split)-1]); + g_strfreev(split); + + return plugin_name; +} |