1
0
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Add function to get plugin name

This commit is contained in:
James Booth 2016-06-22 01:09:39 +01:00
parent 3a3933eff6
commit 620e6a5a37

View File

@ -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;
}