1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Experimenting with python integration for plugins

This commit is contained in:
James Booth 2013-07-21 23:31:09 +01:00
parent cbe3c41abe
commit 4b416ba58e
9 changed files with 124 additions and 5 deletions

2
.gitignore vendored
View File

@ -28,3 +28,5 @@ stamp-h1
valgrind.out
core
bugs/
*.pyc
TODO

View File

@ -21,7 +21,8 @@ profanity_SOURCES = \
src/tools/tinyurl.c src/tools/tinyurl.h \
src/config/accounts.c src/config/accounts.h \
src/config/preferences.c src/config/preferences.h \
src/config/theme.c src/config/theme.h
src/config/theme.c src/config/theme.h \
src/api/apu.h src/api/api.c
TESTS = tests/testsuite
check_PROGRAMS = tests/testsuite
@ -48,6 +49,7 @@ tests_testsuite_SOURCES = \
src/config/accounts.c src/config/accounts.h \
src/config/preferences.c src/config/preferences.h \
src/config/theme.c src/config/theme.h \
src/api/apu.h src/api/api.c
tests/test_roster.c tests/test_common.c tests/test_history.c \
tests/test_autocomplete.c tests/testsuite.c tests/test_parser.c \
tests/test_jid.c

View File

@ -88,11 +88,11 @@ if test "x$enable_notifications" != xno; then
fi
# Default parameters
AM_CFLAGS="-Wall"
AM_CFLAGS="-Wall -I/usr/include/python2.7 -I/usr/include/python2.7 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -L/usr/lib/python2.7/config -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions"
if test "x$PACKAGE_STATUS" = xdevelopment; then
AM_CFLAGS="$AM_CFLAGS -Wunused -Werror"
fi
LIBS="$LIBS $DEPS_LIBS $NOTIFY_LIBS"
LIBS="$LIBS $DEPS_LIBS $NOTIFY_LIBS -lpthread -ldl -lutil -lm -lpython2.7"
AM_CPPFLAGS="$DEPS_CFLAGS $NOTIFY_CFLAGS"

2
plugins/test.py Normal file
View File

@ -0,0 +1,2 @@
def plugin_name():
return "plugin james"

81
src/api/api.c Normal file
View File

@ -0,0 +1,81 @@
/*
* api.c
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <Python.h>
#include "ui/ui.h"
void
api_init(void)
{
PyObject *pName, *pModule, *pFunc;
PyObject *pValue;
Py_Initialize();
pName = PyString_FromString("test");
pModule = PyImport_Import(pName);
Py_DECREF(pName);
if (pModule != NULL) {
pFunc = PyObject_GetAttrString(pModule, "pluginname");
if (pFunc == NULL) {
cons_show("NULL pfunc");
}
if (pFunc && PyCallable_Check(pFunc)) {
pValue = PyObject_CallObject(pFunc, NULL);
if (pValue != NULL) {
cons_show("Plugin loaded");
cons_show("Result of call: %s", PyString_AsString(pValue));
Py_DECREF(pValue);
}
else {
Py_DECREF(pFunc);
Py_DECREF(pModule);
cons_show("Error loading plugin");
return;
}
}
else {
if (PyErr_Occurred())
cons_show("PyErr occurred");
cons_show("Could not find function");
}
Py_XDECREF(pFunc);
Py_DECREF(pModule);
}
else {
cons_show("Failed to load plugin");
return ;
}
Py_Finalize();
return;
}
void
api_prof_cons_show(const char *message)
{
if (message != NULL) {
cons_show("%s", message);
}
}

28
src/api/api.h Normal file
View File

@ -0,0 +1,28 @@
/*
* api.h
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef API_H
#define API_H
void api_init(void);
#endif

View File

@ -31,6 +31,7 @@
#include "profanity.h"
#include "api/api.h"
#include "chat_session.h"
#include "config/accounts.h"
#include "config/preferences.h"
@ -633,6 +634,7 @@ _init(const int disable_tls, char *log_level)
roster_init();
muc_init();
atexit(_shutdown);
api_init();
}
static void

View File

@ -71,11 +71,11 @@ static struct {
static GTimer *reconnect_timer;
static log_level_t _get_log_level(xmpp_log_level_t xmpp_level);
static xmpp_log_level_t _get_xmpp_log_level();
static xmpp_log_level_t _get_xmpp_log_level(void);
static void _xmpp_file_logger(void * const userdata,
const xmpp_log_level_t level, const char * const area,
const char * const msg);
static xmpp_log_t * _xmpp_get_file_logger();
static xmpp_log_t * _xmpp_get_file_logger(void);
static jabber_conn_status_t _jabber_connect(const char * const fulljid,
const char * const passwd, const char * const altdomain);

2
test.py Normal file
View File

@ -0,0 +1,2 @@
def pluginname():
return "plugin james"