From 620e6a5a3764c0dad6c0adb203227e7b8df84083 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 22 Jun 2016 01:09:39 +0100 Subject: Add function to get plugin name --- src/plugins/python_api.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 +#include #include @@ -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; +} -- cgit 1.4.1-2-gfad0